mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
|
package instrumenting
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/zitadel/logging"
|
||
|
"go.opentelemetry.io/otel/attribute"
|
||
|
|
||
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||
|
"github.com/zitadel/zitadel/internal/notification/channels"
|
||
|
"github.com/zitadel/zitadel/internal/telemetry/metrics"
|
||
|
)
|
||
|
|
||
|
func countMessages(ctx context.Context, channel channels.NotificationChannel, successMetricName, errorMetricName string) channels.NotificationChannel {
|
||
|
return channels.HandleMessageFunc(func(message channels.Message) error {
|
||
|
err := channel.HandleMessage(message)
|
||
|
metricName := successMetricName
|
||
|
if err != nil {
|
||
|
metricName = errorMetricName
|
||
|
}
|
||
|
addCount(ctx, metricName, message, err)
|
||
|
return err
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func addCount(ctx context.Context, metricName string, message channels.Message, err error) {
|
||
|
labels := map[string]attribute.Value{
|
||
|
"triggering_event_typey": attribute.StringValue(string(message.GetTriggeringEvent().Type())),
|
||
|
"instance": attribute.StringValue(authz.GetInstance(ctx).InstanceID()),
|
||
|
}
|
||
|
if err != nil {
|
||
|
labels["error"] = attribute.StringValue(err.Error())
|
||
|
}
|
||
|
addCountErr := metrics.AddCount(ctx, metricName, 1, labels)
|
||
|
logging.WithFields("name", metricName, "labels", labels).OnError(addCountErr).Error("incrementing counter metric failed")
|
||
|
}
|