diff --git a/assets/templates/middleware/telemetry b/assets/templates/middleware/telemetry index 876b5eb73b0072a78362fa5de8d0823aa05c660d..32462a68c0746c15d615b651b0eff6744cfbd4af 100644 --- a/assets/templates/middleware/telemetry +++ b/assets/templates/middleware/telemetry @@ -1,14 +1,10 @@ import ( "context" - "strings" "time" - "git.perx.ru/perxis/perxis-go/pkg/items" - "git.perx.ru/perxis/perxis-go/pkg/metrics" - "git.perx.ru/perxis/perxis-go/pkg/schema" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -19,7 +15,6 @@ import ( type {{$decorator}} struct { {{.Interface.Type}} _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -34,7 +29,6 @@ func {{$funcName}} (base {{.Interface.Type}}, instance string, spanDecorator ... d := {{$decorator}} { {{.Interface.Name}}: base, _instance: instance, - serviceName: strings.ToLower("{{ $.Interface.Name }}"), requestMetrics: requestMetrics, } @@ -49,8 +43,8 @@ func {{$funcName}} (base {{.Interface.Type}}, instance string, spanDecorator ... {{if $method.AcceptsContext}} // {{$method.Name}} implements {{$.Interface.Type}} func (_d {{$decorator}}) {{$method.Declaration}} { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "{{ $.Interface.Name }}"), attribute.String("method", "{{ $method.Name }}"), )) diff --git a/images/middleware/telemetry_middleware.go b/images/middleware/telemetry_middleware.go index 35d3bc1469cfe721f521106ef9ee0c764370793a..f608c8fe5f1ad24f6417acbccf9fdda16e6271f1 100644 --- a/images/middleware/telemetry_middleware.go +++ b/images/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/images" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { images.Images _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base images.Images, instance string, spanDecorator ...f d := telemetryMiddleware{ Images: base, _instance: instance, - serviceName: strings.ToLower("Images"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base images.Images, instance string, spanDecorator ...f // Get implements images.Images func (_d telemetryMiddleware) Get(ctx context.Context, source *files.File, opts *images.GetOptions) (result *files.File, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Images"), attribute.String("method", "Get"), )) diff --git a/pkg/clients/middleware/telemetry_middleware.go b/pkg/clients/middleware/telemetry_middleware.go index dd6188fd1eb5ef706f40adb502378d1a710e7517..ee4a2e27bc02ec2bc8385ac0cbb50323e926d3d8 100644 --- a/pkg/clients/middleware/telemetry_middleware.go +++ b/pkg/clients/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/clients" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { clients.Clients _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base clients.Clients, instance string, spanDecorator .. d := telemetryMiddleware{ Clients: base, _instance: instance, - serviceName: strings.ToLower("Clients"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base clients.Clients, instance string, spanDecorator .. // Create implements clients.Clients func (_d telemetryMiddleware) Create(ctx context.Context, client *clients.Client) (created *clients.Client, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "Create"), )) @@ -85,8 +82,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, client *clients.Client // Delete implements clients.Clients func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id str // Enable implements clients.Clients func (_d telemetryMiddleware) Enable(ctx context.Context, spaceId string, id string, enable bool) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "Enable"), )) @@ -154,8 +151,8 @@ func (_d telemetryMiddleware) Enable(ctx context.Context, spaceId string, id str // Get implements clients.Clients func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string) (client *clients.Client, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "Get"), )) @@ -189,8 +186,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string // GetBy implements clients.Clients func (_d telemetryMiddleware) GetBy(ctx context.Context, spaceId string, params *clients.GetByParams) (client *clients.Client, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "GetBy"), )) @@ -224,8 +221,8 @@ func (_d telemetryMiddleware) GetBy(ctx context.Context, spaceId string, params // List implements clients.Clients func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (clients []*clients.Client, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "List"), )) @@ -258,8 +255,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (clients // Update implements clients.Clients func (_d telemetryMiddleware) Update(ctx context.Context, client *clients.Client) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Clients"), attribute.String("method", "Update"), )) diff --git a/pkg/collaborators/middleware/telemetry_middleware.go b/pkg/collaborators/middleware/telemetry_middleware.go index 29dee6e2516107adb1fd6fd9bb1637d1ad948726..13f089773e58513276fd01dd2e782b9ced83a24a 100644 --- a/pkg/collaborators/middleware/telemetry_middleware.go +++ b/pkg/collaborators/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/collaborators" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { collaborators.Collaborators _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base collaborators.Collaborators, instance string, span d := telemetryMiddleware{ Collaborators: base, _instance: instance, - serviceName: strings.ToLower("Collaborators"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base collaborators.Collaborators, instance string, span // Get implements collaborators.Collaborators func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, subject string) (role string, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collaborators"), attribute.String("method", "Get"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, subject s // ListCollaborators implements collaborators.Collaborators func (_d telemetryMiddleware) ListCollaborators(ctx context.Context, spaceId string) (collaborators []*collaborators.Collaborator, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collaborators"), attribute.String("method", "ListCollaborators"), )) @@ -120,8 +117,8 @@ func (_d telemetryMiddleware) ListCollaborators(ctx context.Context, spaceId str // ListSpaces implements collaborators.Collaborators func (_d telemetryMiddleware) ListSpaces(ctx context.Context, subject string) (spaces []*collaborators.Collaborator, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collaborators"), attribute.String("method", "ListSpaces"), )) @@ -154,8 +151,8 @@ func (_d telemetryMiddleware) ListSpaces(ctx context.Context, subject string) (s // Remove implements collaborators.Collaborators func (_d telemetryMiddleware) Remove(ctx context.Context, spaceId string, subject string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collaborators"), attribute.String("method", "Remove"), )) @@ -188,8 +185,8 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, spaceId string, subjec // Set implements collaborators.Collaborators func (_d telemetryMiddleware) Set(ctx context.Context, spaceId string, subject string, role string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collaborators"), attribute.String("method", "Set"), )) diff --git a/pkg/collections/middleware/telemetry_middleware.go b/pkg/collections/middleware/telemetry_middleware.go index d172e7f39c6801d9787325a56151f65fa82c23fc..8ba14244d576e531468f34ae1943b7b7f227e1aa 100644 --- a/pkg/collections/middleware/telemetry_middleware.go +++ b/pkg/collections/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/collections" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/schema" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { collections.Collections _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base collections.Collections, instance string, spanDeco d := telemetryMiddleware{ Collections: base, _instance: instance, - serviceName: strings.ToLower("Collections"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base collections.Collections, instance string, spanDeco // Create implements collections.Collections func (_d telemetryMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "Create"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection // Delete implements collections.Collections func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "Delete"), )) @@ -121,8 +118,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId // Get implements collections.Collections func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "Get"), )) @@ -158,8 +155,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str // List implements collections.Collections func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "List"), )) @@ -194,8 +191,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st // SetSchema implements collections.Collections func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "SetSchema"), )) @@ -230,8 +227,8 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env // SetState implements collections.Collections func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "SetState"), )) @@ -266,8 +263,8 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envI // Update implements collections.Collections func (_d telemetryMiddleware) Update(ctx context.Context, coll *collections.Collection) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Collections"), attribute.String("method", "Update"), )) diff --git a/pkg/delivery/middleware/telemetry_middleware.go b/pkg/delivery/middleware/telemetry_middleware.go index 0b0e1a5e0cbaee3ff333c2f29afab9881fadc49a..c4f11f370f7d0b9c4f8e878a6a79d73b8fc90a42 100644 --- a/pkg/delivery/middleware/telemetry_middleware.go +++ b/pkg/delivery/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/collections" @@ -19,7 +18,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -27,7 +26,6 @@ import ( type telemetryMiddleware struct { delivery.Delivery _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -42,7 +40,6 @@ func TelemetryMiddleware(base delivery.Delivery, instance string, spanDecorator d := telemetryMiddleware{ Delivery: base, _instance: instance, - serviceName: strings.ToLower("Delivery"), requestMetrics: requestMetrics, } @@ -55,8 +52,8 @@ func TelemetryMiddleware(base delivery.Delivery, instance string, spanDecorator // Aggregate implements delivery.Delivery func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregatePublishedOptions) (result map[string]interface{}, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "Aggregate"), )) @@ -93,8 +90,8 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env // FindItems implements delivery.Delivery func (_d telemetryMiddleware) FindItems(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindPublishedOptions) (items []*items.Item, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "FindItems"), )) @@ -132,8 +129,8 @@ func (_d telemetryMiddleware) FindItems(ctx context.Context, spaceId string, env // GetCollection implements delivery.Delivery func (_d telemetryMiddleware) GetCollection(ctx context.Context, spaceId string, envId string, collectionId string) (collection *collections.Collection, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "GetCollection"), )) @@ -168,8 +165,8 @@ func (_d telemetryMiddleware) GetCollection(ctx context.Context, spaceId string, // GetEnvironment implements delivery.Delivery func (_d telemetryMiddleware) GetEnvironment(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "GetEnvironment"), )) @@ -203,8 +200,8 @@ func (_d telemetryMiddleware) GetEnvironment(ctx context.Context, spaceId string // GetItem implements delivery.Delivery func (_d telemetryMiddleware) GetItem(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "GetItem"), )) @@ -241,8 +238,8 @@ func (_d telemetryMiddleware) GetItem(ctx context.Context, spaceId string, envId // ListCollections implements delivery.Delivery func (_d telemetryMiddleware) ListCollections(ctx context.Context, spaceId string, envId string) (collections []*collections.Collection, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "ListCollections"), )) @@ -276,8 +273,8 @@ func (_d telemetryMiddleware) ListCollections(ctx context.Context, spaceId strin // ListEnvironments implements delivery.Delivery func (_d telemetryMiddleware) ListEnvironments(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "ListEnvironments"), )) @@ -310,8 +307,8 @@ func (_d telemetryMiddleware) ListEnvironments(ctx context.Context, spaceId stri // ListLocales implements delivery.Delivery func (_d telemetryMiddleware) ListLocales(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Delivery"), attribute.String("method", "ListLocales"), )) diff --git a/pkg/environments/middleware/telemetry_middleware.go b/pkg/environments/middleware/telemetry_middleware.go index fb845ba7b6e5c378669bd7b0de7df9486df88830..c5952405c19f84810bca120bab05124a53e13f50 100644 --- a/pkg/environments/middleware/telemetry_middleware.go +++ b/pkg/environments/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/environments" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { environments.Environments _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base environments.Environments, instance string, spanDe d := telemetryMiddleware{ Environments: base, _instance: instance, - serviceName: strings.ToLower("Environments"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base environments.Environments, instance string, spanDe // Create implements environments.Environments func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Environment) (created *environments.Environment, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "Create"), )) @@ -85,8 +82,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Envi // Delete implements environments.Environments func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId // Get implements environments.Environments func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "Get"), )) @@ -154,8 +151,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str // List implements environments.Environments func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "List"), )) @@ -188,8 +185,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (envs [] // Migrate implements environments.Environments func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "Migrate"), )) @@ -223,8 +220,8 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId // RemoveAlias implements environments.Environments func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "RemoveAlias"), )) @@ -258,8 +255,8 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e // SetAlias implements environments.Environments func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "SetAlias"), )) @@ -293,8 +290,8 @@ func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envI // Update implements environments.Environments func (_d telemetryMiddleware) Update(ctx context.Context, env *environments.Environment) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Environments"), attribute.String("method", "Update"), )) diff --git a/pkg/files/middleware/telemetry_middleware.go b/pkg/files/middleware/telemetry_middleware.go index 0836f12116e4c8479bb4df285f40b8663ccfdb32..021759c6a32d6f8da1cd711d0d26b84d07b6a145 100644 --- a/pkg/files/middleware/telemetry_middleware.go +++ b/pkg/files/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/files" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { files.Files _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base files.Files, instance string, spanDecorator ...fun d := telemetryMiddleware{ Files: base, _instance: instance, - serviceName: strings.ToLower("Files"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base files.Files, instance string, spanDecorator ...fun // AbortUpload implements files.Files func (_d telemetryMiddleware) AbortUpload(ctx context.Context, upload *files.MultipartUpload) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "AbortUpload"), )) @@ -84,8 +81,8 @@ func (_d telemetryMiddleware) AbortUpload(ctx context.Context, upload *files.Mul // CompleteUpload implements files.Files func (_d telemetryMiddleware) CompleteUpload(ctx context.Context, upload *files.MultipartUpload) (u *files.MultipartUpload, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "CompleteUpload"), )) @@ -118,8 +115,8 @@ func (_d telemetryMiddleware) CompleteUpload(ctx context.Context, upload *files. // DeleteFile implements files.Files func (_d telemetryMiddleware) DeleteFile(ctx context.Context, file *files.File) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "DeleteFile"), )) @@ -151,8 +148,8 @@ func (_d telemetryMiddleware) DeleteFile(ctx context.Context, file *files.File) // GetFile implements files.Files func (_d telemetryMiddleware) GetFile(ctx context.Context, file *files.File) (f *files.File, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "GetFile"), )) @@ -185,8 +182,8 @@ func (_d telemetryMiddleware) GetFile(ctx context.Context, file *files.File) (f // MoveUpload implements files.Files func (_d telemetryMiddleware) MoveUpload(ctx context.Context, upload *files.MultipartUpload) (file *files.File, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "MoveUpload"), )) @@ -219,8 +216,8 @@ func (_d telemetryMiddleware) MoveUpload(ctx context.Context, upload *files.Mult // StartUpload implements files.Files func (_d telemetryMiddleware) StartUpload(ctx context.Context, upload *files.MultipartUpload) (u *files.MultipartUpload, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "StartUpload"), )) @@ -253,8 +250,8 @@ func (_d telemetryMiddleware) StartUpload(ctx context.Context, upload *files.Mul // Upload implements files.Files func (_d telemetryMiddleware) Upload(ctx context.Context, file *files.File) (u *files.Upload, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Files"), attribute.String("method", "Upload"), )) diff --git a/pkg/invitations/middleware/telemetry_middleware.go b/pkg/invitations/middleware/telemetry_middleware.go index cc646f4e030b2eb7c8ab31e6c3c0d495d534dc33..98a2e514fcd92aa186bc012d64a0a161e3108144 100644 --- a/pkg/invitations/middleware/telemetry_middleware.go +++ b/pkg/invitations/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/invitations" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/options" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { invitations.Invitations _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base invitations.Invitations, instance string, spanDeco d := telemetryMiddleware{ Invitations: base, _instance: instance, - serviceName: strings.ToLower("Invitations"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base invitations.Invitations, instance string, spanDeco // Accept implements invitations.Invitations func (_d telemetryMiddleware) Accept(ctx context.Context, invitationId string, userId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Invitations"), attribute.String("method", "Accept"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Accept(ctx context.Context, invitationId string, u // Create implements invitations.Invitations func (_d telemetryMiddleware) Create(ctx context.Context, invitation *invitations.Invitation) (created *invitations.Invitation, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Invitations"), attribute.String("method", "Create"), )) @@ -120,8 +117,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, invitation *invitation // Delete implements invitations.Invitations func (_d telemetryMiddleware) Delete(ctx context.Context, invitationId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Invitations"), attribute.String("method", "Delete"), )) @@ -153,8 +150,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, invitationId string) ( // Find implements invitations.Invitations func (_d telemetryMiddleware) Find(ctx context.Context, filter *invitations.Filter, opts *options.FindOptions) (invitations []*invitations.Invitation, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Invitations"), attribute.String("method", "Find"), )) @@ -189,8 +186,8 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *invitations.Filt // Get implements invitations.Invitations func (_d telemetryMiddleware) Get(ctx context.Context, invitationId string) (invitation *invitations.Invitation, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Invitations"), attribute.String("method", "Get"), )) diff --git a/pkg/items/middleware/telemetry_middleware.go b/pkg/items/middleware/telemetry_middleware.go index 87a0c4a5e5aadd9b59c0e85fc6146a9a0ba67288..1f931cbabc6532d7b848279c3633f76cc96bc47f 100644 --- a/pkg/items/middleware/telemetry_middleware.go +++ b/pkg/items/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/items" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/schema" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { items.Items _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base items.Items, instance string, spanDecorator ...fun d := telemetryMiddleware{ Items: base, _instance: instance, - serviceName: strings.ToLower("Items"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base items.Items, instance string, spanDecorator ...fun // Aggregate implements items.Items func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregateOptions) (result map[string]interface{}, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Aggregate"), )) @@ -90,8 +87,8 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env // AggregatePublished implements items.Items func (_d telemetryMiddleware) AggregatePublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregatePublishedOptions) (result map[string]interface{}, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "AggregatePublished"), )) @@ -128,8 +125,8 @@ func (_d telemetryMiddleware) AggregatePublished(ctx context.Context, spaceId st // Archive implements items.Items func (_d telemetryMiddleware) Archive(ctx context.Context, item *items.Item, options ...*items.ArchiveOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Archive"), )) @@ -162,8 +159,8 @@ func (_d telemetryMiddleware) Archive(ctx context.Context, item *items.Item, opt // Create implements items.Items func (_d telemetryMiddleware) Create(ctx context.Context, item *items.Item, opts ...*items.CreateOptions) (created *items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Create"), )) @@ -197,8 +194,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, item *items.Item, opts // Delete implements items.Items func (_d telemetryMiddleware) Delete(ctx context.Context, item *items.Item, options ...*items.DeleteOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Delete"), )) @@ -231,8 +228,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, item *items.Item, opti // Find implements items.Items func (_d telemetryMiddleware) Find(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindOptions) (items []*items.Item, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Find"), )) @@ -270,8 +267,8 @@ func (_d telemetryMiddleware) Find(ctx context.Context, spaceId string, envId st // FindArchived implements items.Items func (_d telemetryMiddleware) FindArchived(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindArchivedOptions) (items []*items.Item, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "FindArchived"), )) @@ -309,8 +306,8 @@ func (_d telemetryMiddleware) FindArchived(ctx context.Context, spaceId string, // FindPublished implements items.Items func (_d telemetryMiddleware) FindPublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindPublishedOptions) (items []*items.Item, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "FindPublished"), )) @@ -348,8 +345,8 @@ func (_d telemetryMiddleware) FindPublished(ctx context.Context, spaceId string, // Get implements items.Items func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Get"), )) @@ -386,8 +383,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str // GetPublished implements items.Items func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "GetPublished"), )) @@ -424,8 +421,8 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, // GetRevision implements items.Items func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "GetRevision"), )) @@ -463,8 +460,8 @@ func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, e // Introspect implements items.Items func (_d telemetryMiddleware) Introspect(ctx context.Context, item *items.Item, opts ...*items.IntrospectOptions) (itm *items.Item, sch *schema.Schema, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Introspect"), )) @@ -499,8 +496,8 @@ func (_d telemetryMiddleware) Introspect(ctx context.Context, item *items.Item, // ListRevisions implements items.Items func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "ListRevisions"), )) @@ -537,8 +534,8 @@ func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, // Publish implements items.Items func (_d telemetryMiddleware) Publish(ctx context.Context, item *items.Item, options ...*items.PublishOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Publish"), )) @@ -571,8 +568,8 @@ func (_d telemetryMiddleware) Publish(ctx context.Context, item *items.Item, opt // Unarchive implements items.Items func (_d telemetryMiddleware) Unarchive(ctx context.Context, item *items.Item, options ...*items.UnarchiveOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Unarchive"), )) @@ -605,8 +602,8 @@ func (_d telemetryMiddleware) Unarchive(ctx context.Context, item *items.Item, o // Undelete implements items.Items func (_d telemetryMiddleware) Undelete(ctx context.Context, item *items.Item, options ...*items.UndeleteOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Undelete"), )) @@ -639,8 +636,8 @@ func (_d telemetryMiddleware) Undelete(ctx context.Context, item *items.Item, op // Unpublish implements items.Items func (_d telemetryMiddleware) Unpublish(ctx context.Context, item *items.Item, options ...*items.UnpublishOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Unpublish"), )) @@ -673,8 +670,8 @@ func (_d telemetryMiddleware) Unpublish(ctx context.Context, item *items.Item, o // Update implements items.Items func (_d telemetryMiddleware) Update(ctx context.Context, item *items.Item, options ...*items.UpdateOptions) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Items"), attribute.String("method", "Update"), )) diff --git a/pkg/locales/middleware/telemetry_middleware.go b/pkg/locales/middleware/telemetry_middleware.go index 08740aebedaddbe8a78c2c6679489f4965819379..79a770964d06cee0893bc702de312d5365ef671a 100644 --- a/pkg/locales/middleware/telemetry_middleware.go +++ b/pkg/locales/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/locales" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { locales.Locales _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base locales.Locales, instance string, spanDecorator .. d := telemetryMiddleware{ Locales: base, _instance: instance, - serviceName: strings.ToLower("Locales"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base locales.Locales, instance string, spanDecorator .. // Create implements locales.Locales func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale) (created *locales.Locale, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Locales"), attribute.String("method", "Create"), )) @@ -85,8 +82,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale // Delete implements locales.Locales func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Locales"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, locale // List implements locales.Locales func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Locales"), attribute.String("method", "List"), )) diff --git a/pkg/members/middleware/telemetry_middleware.go b/pkg/members/middleware/telemetry_middleware.go index 1e3d8e73ecb7e6990b95e8ac46939e97723d74ba..b7d6f32b23bf47b38014c761008a9d441d86c4c5 100644 --- a/pkg/members/middleware/telemetry_middleware.go +++ b/pkg/members/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/members" "git.perx.ru/perxis/perxis-go/pkg/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { members.Members _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base members.Members, instance string, spanDecorator .. d := telemetryMiddleware{ Members: base, _instance: instance, - serviceName: strings.ToLower("Members"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base members.Members, instance string, spanDecorator .. // Get implements members.Members func (_d telemetryMiddleware) Get(ctx context.Context, orgId string, userId string) (role members.Role, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "Get"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string, userId stri // ListMembers implements members.Members func (_d telemetryMiddleware) ListMembers(ctx context.Context, orgId string) (members []*members.Member, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "ListMembers"), )) @@ -120,8 +117,8 @@ func (_d telemetryMiddleware) ListMembers(ctx context.Context, orgId string) (me // ListOrganizations implements members.Members func (_d telemetryMiddleware) ListOrganizations(ctx context.Context, userId string) (organizations []*members.Member, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "ListOrganizations"), )) @@ -154,8 +151,8 @@ func (_d telemetryMiddleware) ListOrganizations(ctx context.Context, userId stri // Remove implements members.Members func (_d telemetryMiddleware) Remove(ctx context.Context, orgId string, userId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "Remove"), )) @@ -188,8 +185,8 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, orgId string, userId s // RemoveAll implements members.Members func (_d telemetryMiddleware) RemoveAll(ctx context.Context, orgId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "RemoveAll"), )) @@ -221,8 +218,8 @@ func (_d telemetryMiddleware) RemoveAll(ctx context.Context, orgId string) (err // Set implements members.Members func (_d telemetryMiddleware) Set(ctx context.Context, orgId string, userId string, role members.Role) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Members"), attribute.String("method", "Set"), )) diff --git a/pkg/organizations/middleware/telemetry_middleware.go b/pkg/organizations/middleware/telemetry_middleware.go index da5c010098213ed5cd0a53cc9f19612ee7fa4168..4f9c21153bc419449eefb13daadeeb71cd7aad06 100644 --- a/pkg/organizations/middleware/telemetry_middleware.go +++ b/pkg/organizations/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/metrics" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/organizations" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { organizations.Organizations _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base organizations.Organizations, instance string, span d := telemetryMiddleware{ Organizations: base, _instance: instance, - serviceName: strings.ToLower("Organizations"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base organizations.Organizations, instance string, span // Create implements organizations.Organizations func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Organization) (created *organizations.Organization, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Organizations"), attribute.String("method", "Create"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Org // Delete implements organizations.Organizations func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Organizations"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err err // Find implements organizations.Organizations func (_d telemetryMiddleware) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) (orgs []*organizations.Organization, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Organizations"), attribute.String("method", "Find"), )) @@ -155,8 +152,8 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *organizations.Fi // Get implements organizations.Organizations func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Organizations"), attribute.String("method", "Get"), )) @@ -189,8 +186,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organ // Update implements organizations.Organizations func (_d telemetryMiddleware) Update(ctx context.Context, org *organizations.Organization) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Organizations"), attribute.String("method", "Update"), )) diff --git a/pkg/references/middleware/telemetry_middleware.go b/pkg/references/middleware/telemetry_middleware.go index 1d93caac6789106a35573e531716abc56a2e3bc5..bc4f3ebc3945db814c469fdf91c92779a73f51cf 100644 --- a/pkg/references/middleware/telemetry_middleware.go +++ b/pkg/references/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/items" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/references" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { references.References _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base references.References, instance string, spanDecora d := telemetryMiddleware{ References: base, _instance: instance, - serviceName: strings.ToLower("References"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base references.References, instance string, spanDecora // Get implements references.References func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, references []*references.Reference) (items []*items.Item, notfound []*references.Reference, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "References"), attribute.String("method", "Get"), )) @@ -89,8 +86,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str // Publish implements references.References func (_d telemetryMiddleware) Publish(ctx context.Context, spaceId string, envId string, references []*references.Reference, recursive bool, force bool) (published []*references.Reference, notfound []*references.Reference, unpublished []*references.Reference, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "References"), attribute.String("method", "Publish"), )) diff --git a/pkg/roles/middleware/telemetry_middleware.go b/pkg/roles/middleware/telemetry_middleware.go index 5365a18d8e5b127652834f2f30ad93727a3dffb3..703e3b93584316ecb1dcddb69497a32235f2dc00 100644 --- a/pkg/roles/middleware/telemetry_middleware.go +++ b/pkg/roles/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/metrics" "git.perx.ru/perxis/perxis-go/pkg/roles" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { roles.Roles _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base roles.Roles, instance string, spanDecorator ...fun d := telemetryMiddleware{ Roles: base, _instance: instance, - serviceName: strings.ToLower("Roles"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base roles.Roles, instance string, spanDecorator ...fun // Create implements roles.Roles func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (created *roles.Role, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Roles"), attribute.String("method", "Create"), )) @@ -85,8 +82,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (cre // Delete implements roles.Roles func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Roles"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId // Get implements roles.Roles func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Roles"), attribute.String("method", "Get"), )) @@ -154,8 +151,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId st // List implements roles.Roles func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (roles []*roles.Role, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Roles"), attribute.String("method", "List"), )) @@ -188,8 +185,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (roles [ // Update implements roles.Roles func (_d telemetryMiddleware) Update(ctx context.Context, role *roles.Role) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Roles"), attribute.String("method", "Update"), )) diff --git a/pkg/spaces/middleware/telemetry_middleware.go b/pkg/spaces/middleware/telemetry_middleware.go index 9d7a40948549cc110e0a3b971b0bfd84f49fbd5f..c52facae57f25e0f91e784ff57f9cfe2e1b159f8 100644 --- a/pkg/spaces/middleware/telemetry_middleware.go +++ b/pkg/spaces/middleware/telemetry_middleware.go @@ -8,14 +8,13 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/metrics" "git.perx.ru/perxis/perxis-go/pkg/spaces" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -23,7 +22,6 @@ import ( type telemetryMiddleware struct { spaces.Spaces _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -38,7 +36,6 @@ func TelemetryMiddleware(base spaces.Spaces, instance string, spanDecorator ...f d := telemetryMiddleware{ Spaces: base, _instance: instance, - serviceName: strings.ToLower("Spaces"), requestMetrics: requestMetrics, } @@ -51,8 +48,8 @@ func TelemetryMiddleware(base spaces.Spaces, instance string, spanDecorator ...f // AbortTransfer implements spaces.Spaces func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "AbortTransfer"), )) @@ -84,8 +81,8 @@ func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) // Create implements spaces.Spaces func (_d telemetryMiddleware) Create(ctx context.Context, space *spaces.Space) (created *spaces.Space, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Create"), )) @@ -118,8 +115,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, space *spaces.Space) ( // Delete implements spaces.Spaces func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Delete"), )) @@ -151,8 +148,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err e // Get implements spaces.Spaces func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Get"), )) @@ -185,8 +182,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *s // List implements spaces.Spaces func (_d telemetryMiddleware) List(ctx context.Context, orgId string) (spaces []*spaces.Space, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "List"), )) @@ -219,8 +216,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, orgId string) (spaces [] // ListTransfers implements spaces.Spaces func (_d telemetryMiddleware) ListTransfers(ctx context.Context, orgID string) (spaces []*spaces.Space, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "ListTransfers"), )) @@ -253,8 +250,8 @@ func (_d telemetryMiddleware) ListTransfers(ctx context.Context, orgID string) ( // Move implements spaces.Spaces func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Move"), )) @@ -287,8 +284,8 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st // Transfer implements spaces.Spaces func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Transfer"), )) @@ -321,8 +318,8 @@ func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, tran // Update implements spaces.Spaces func (_d telemetryMiddleware) Update(ctx context.Context, space *spaces.Space) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "Update"), )) @@ -354,8 +351,8 @@ func (_d telemetryMiddleware) Update(ctx context.Context, space *spaces.Space) ( // UpdateConfig implements spaces.Spaces func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Spaces"), attribute.String("method", "UpdateConfig"), )) diff --git a/pkg/users/middleware/telemetry_middleware.go b/pkg/users/middleware/telemetry_middleware.go index 6d39a58d2f7e08f614b8cf1d1ae0457315eb58df..e680ae4308b4528fd4534f460ba858c59bf047cf 100644 --- a/pkg/users/middleware/telemetry_middleware.go +++ b/pkg/users/middleware/telemetry_middleware.go @@ -8,7 +8,6 @@ package middleware import ( "context" - "strings" "time" "git.perx.ru/perxis/perxis-go/pkg/metrics" @@ -16,7 +15,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/users" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - metricotel "go.opentelemetry.io/otel/metric" + otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -24,7 +23,6 @@ import ( type telemetryMiddleware struct { users.Users _instance string - serviceName string requestMetrics *metrics.RequestMetrics _spanDecorator func(span trace.Span, params, results map[string]interface{}) } @@ -39,7 +37,6 @@ func TelemetryMiddleware(base users.Users, instance string, spanDecorator ...fun d := telemetryMiddleware{ Users: base, _instance: instance, - serviceName: strings.ToLower("Users"), requestMetrics: requestMetrics, } @@ -52,8 +49,8 @@ func TelemetryMiddleware(base users.Users, instance string, spanDecorator ...fun // Create implements users.Users func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "Create"), )) @@ -86,8 +83,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (u // Delete implements users.Users func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "Delete"), )) @@ -119,8 +116,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err er // Find implements users.Users func (_d telemetryMiddleware) Find(ctx context.Context, filter *users.Filter, options *options.FindOptions) (users []*users.User, total int, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "Find"), )) @@ -155,8 +152,8 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *users.Filter, op // Get implements users.Users func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "Get"), )) @@ -189,8 +186,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *use // GetByIdentity implements users.Users func (_d telemetryMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "GetByIdentity"), )) @@ -223,8 +220,8 @@ func (_d telemetryMiddleware) GetByIdentity(ctx context.Context, identity string // Update implements users.Users func (_d telemetryMiddleware) Update(ctx context.Context, update *users.User) (err error) { - attributes := metricotel.WithAttributeSet(attribute.NewSet( - attribute.String("service", _d.serviceName), + attributes := otelmetric.WithAttributeSet(attribute.NewSet( + attribute.String("service", "Users"), attribute.String("method", "Update"), ))