From 0d85618c2e5b8e7bb127837baa2c1740312e2d56 Mon Sep 17 00:00:00 2001 From: ensiouel <ensiouel@gmail.com> Date: Thu, 21 Dec 2023 19:37:17 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=80=D0=B0=20telemetry=20middleware=20=D0=B8=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D1=8B=20middlewares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/templates/middleware/telemetry | 15 +- images/middleware/telemetry_middleware.go | 15 +- .../middleware/telemetry_middleware.go | 63 ++++---- .../middleware/telemetry_middleware.go | 47 +++--- .../middleware/telemetry_middleware.go | 63 ++++---- .../middleware/telemetry_middleware.go | 71 ++++---- .../middleware/telemetry_middleware.go | 71 ++++---- pkg/files/middleware/telemetry_middleware.go | 63 ++++---- .../middleware/telemetry_middleware.go | 47 +++--- pkg/items/middleware/telemetry_middleware.go | 151 +++++++++--------- .../middleware/telemetry_middleware.go | 31 ++-- .../middleware/telemetry_middleware.go | 55 ++++--- .../middleware/telemetry_middleware.go | 47 +++--- .../middleware/telemetry_middleware.go | 23 +-- pkg/roles/middleware/telemetry_middleware.go | 47 +++--- pkg/spaces/middleware/telemetry_middleware.go | 87 +++++----- pkg/users/middleware/telemetry_middleware.go | 55 ++++--- 17 files changed, 518 insertions(+), 433 deletions(-) diff --git a/assets/templates/middleware/telemetry b/assets/templates/middleware/telemetry index 0640645f..39653dde 100644 --- a/assets/templates/middleware/telemetry +++ b/assets/templates/middleware/telemetry @@ -25,7 +25,12 @@ type {{$decorator}} struct { } // {{$funcName}} returns {{$decorator}} -func {{$funcName}} (base {{.Interface.Type}}, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) {{$decorator}} { +func {{$funcName}} (base {{.Interface.Type}}, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) {{$decorator}} { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := {{$decorator}} { {{.Interface.Name}}: base, _instance: instance, @@ -44,10 +49,10 @@ func {{$funcName}} (base {{.Interface.Type}}, instance string, requestMetrics *m {{if $method.AcceptsContext}} // {{$method.Name}} implements {{$.Interface.Type}} func (_d {{$decorator}}) {{$method.Declaration}} { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("{{ $method.Name }}"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "{{ $method.Name }}"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/images/middleware/telemetry_middleware.go b/images/middleware/telemetry_middleware.go index 607d7e94..35d3bc14 100644 --- a/images/middleware/telemetry_middleware.go +++ b/images/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base images.Images, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base images.Images, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Images: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base images.Images, instance string, requestMetrics *me // Get implements images.Images func (_d telemetryMiddleware) Get(ctx context.Context, source *files.File, opts *images.GetOptions) (result *files.File, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/clients/middleware/telemetry_middleware.go b/pkg/clients/middleware/telemetry_middleware.go index 29d91606..dd6188fd 100644 --- a/pkg/clients/middleware/telemetry_middleware.go +++ b/pkg/clients/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base clients.Clients, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base clients.Clients, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Clients: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base clients.Clients, instance string, requestMetrics * // Create implements clients.Clients func (_d telemetryMiddleware) Create(ctx context.Context, client *clients.Client) (created *clients.Client, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -80,10 +85,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Enable"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Enable"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -149,10 +154,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -184,10 +189,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetBy"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetBy"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -219,10 +224,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -253,10 +258,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/collaborators/middleware/telemetry_middleware.go b/pkg/collaborators/middleware/telemetry_middleware.go index 1989419b..29dee6e2 100644 --- a/pkg/collaborators/middleware/telemetry_middleware.go +++ b/pkg/collaborators/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base collaborators.Collaborators, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base collaborators.Collaborators, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Collaborators: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base collaborators.Collaborators, instance string, requ // Get implements collaborators.Collaborators func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, subject string) (role string, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListCollaborators"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListCollaborators"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -115,10 +120,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListSpaces"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListSpaces"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -149,10 +154,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Remove"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Remove"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -183,10 +188,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Set"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Set"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/collections/middleware/telemetry_middleware.go b/pkg/collections/middleware/telemetry_middleware.go index 51d2fc76..d172e7f3 100644 --- a/pkg/collections/middleware/telemetry_middleware.go +++ b/pkg/collections/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base collections.Collections, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base collections.Collections, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Collections: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base collections.Collections, instance string, requestM // Create implements collections.Collections func (_d telemetryMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -116,10 +121,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -153,10 +158,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -189,10 +194,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("SetSchema"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "SetSchema"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -225,10 +230,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("SetState"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "SetState"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -261,10 +266,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/delivery/middleware/telemetry_middleware.go b/pkg/delivery/middleware/telemetry_middleware.go index 1f5a62c5..0b0e1a5e 100644 --- a/pkg/delivery/middleware/telemetry_middleware.go +++ b/pkg/delivery/middleware/telemetry_middleware.go @@ -33,7 +33,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base delivery.Delivery, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base delivery.Delivery, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Delivery: base, _instance: instance, @@ -50,10 +55,10 @@ func TelemetryMiddleware(base delivery.Delivery, instance string, requestMetrics // 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Aggregate"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Aggregate"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -88,10 +93,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("FindItems"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "FindItems"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -127,10 +132,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetCollection"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetCollection"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -163,10 +168,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetEnvironment"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetEnvironment"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -198,10 +203,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetItem"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetItem"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -236,10 +241,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListCollections"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListCollections"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -271,10 +276,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListEnvironments"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListEnvironments"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -305,10 +310,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListLocales"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListLocales"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/environments/middleware/telemetry_middleware.go b/pkg/environments/middleware/telemetry_middleware.go index b156a188..fb845ba7 100644 --- a/pkg/environments/middleware/telemetry_middleware.go +++ b/pkg/environments/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base environments.Environments, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base environments.Environments, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Environments: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base environments.Environments, instance string, reques // Create implements environments.Environments func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Environment) (created *environments.Environment, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -80,10 +85,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -149,10 +154,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -183,10 +188,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Migrate"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Migrate"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -218,10 +223,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("RemoveAlias"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "RemoveAlias"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -253,10 +258,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("SetAlias"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "SetAlias"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -288,10 +293,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/files/middleware/telemetry_middleware.go b/pkg/files/middleware/telemetry_middleware.go index 6a79a85a..0836f121 100644 --- a/pkg/files/middleware/telemetry_middleware.go +++ b/pkg/files/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base files.Files, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base files.Files, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Files: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base files.Files, instance string, requestMetrics *metr // AbortUpload implements files.Files func (_d telemetryMiddleware) AbortUpload(ctx context.Context, upload *files.MultipartUpload) (err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("AbortUpload"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "AbortUpload"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -79,10 +84,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("CompleteUpload"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "CompleteUpload"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -113,10 +118,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("DeleteFile"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "DeleteFile"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -146,10 +151,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetFile"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetFile"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -180,10 +185,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("MoveUpload"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "MoveUpload"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -214,10 +219,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("StartUpload"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "StartUpload"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -248,10 +253,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Upload"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Upload"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/invitations/middleware/telemetry_middleware.go b/pkg/invitations/middleware/telemetry_middleware.go index 8144176f..cc646f4e 100644 --- a/pkg/invitations/middleware/telemetry_middleware.go +++ b/pkg/invitations/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base invitations.Invitations, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base invitations.Invitations, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Invitations: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base invitations.Invitations, instance string, requestM // Accept implements invitations.Invitations func (_d telemetryMiddleware) Accept(ctx context.Context, invitationId string, userId string) (err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Accept"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Accept"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -115,10 +120,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -148,10 +153,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Find"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Find"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -184,10 +189,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/items/middleware/telemetry_middleware.go b/pkg/items/middleware/telemetry_middleware.go index b0d440d5..87a0c4a5 100644 --- a/pkg/items/middleware/telemetry_middleware.go +++ b/pkg/items/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base items.Items, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base items.Items, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Items: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base items.Items, instance string, requestMetrics *metr // 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Aggregate"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Aggregate"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -85,10 +90,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("AggregatePublished"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "AggregatePublished"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -123,10 +128,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Archive"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Archive"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -157,10 +162,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -192,10 +197,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -226,10 +231,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Find"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Find"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -265,10 +270,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("FindArchived"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "FindArchived"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -304,10 +309,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("FindPublished"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "FindPublished"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -343,10 +348,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -381,10 +386,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetPublished"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetPublished"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -419,10 +424,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetRevision"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetRevision"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -458,10 +463,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Introspect"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Introspect"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -494,10 +499,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListRevisions"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListRevisions"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -532,10 +537,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Publish"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Publish"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -566,10 +571,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Unarchive"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Unarchive"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -600,10 +605,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Undelete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Undelete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -634,10 +639,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Unpublish"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Unpublish"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -668,10 +673,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/locales/middleware/telemetry_middleware.go b/pkg/locales/middleware/telemetry_middleware.go index 2abc54ed..08740aeb 100644 --- a/pkg/locales/middleware/telemetry_middleware.go +++ b/pkg/locales/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base locales.Locales, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base locales.Locales, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Locales: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base locales.Locales, instance string, requestMetrics * // Create implements locales.Locales func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale) (created *locales.Locale, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -80,10 +85,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/members/middleware/telemetry_middleware.go b/pkg/members/middleware/telemetry_middleware.go index 40b0dcef..1e3d8e73 100644 --- a/pkg/members/middleware/telemetry_middleware.go +++ b/pkg/members/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base members.Members, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base members.Members, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Members: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base members.Members, instance string, requestMetrics * // Get implements members.Members func (_d telemetryMiddleware) Get(ctx context.Context, orgId string, userId string) (role members.Role, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListMembers"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListMembers"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -115,10 +120,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListOrganizations"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListOrganizations"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -149,10 +154,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Remove"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Remove"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -183,10 +188,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("RemoveAll"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "RemoveAll"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -216,10 +221,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Set"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Set"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/organizations/middleware/telemetry_middleware.go b/pkg/organizations/middleware/telemetry_middleware.go index 8e4a556e..da5c0100 100644 --- a/pkg/organizations/middleware/telemetry_middleware.go +++ b/pkg/organizations/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base organizations.Organizations, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base organizations.Organizations, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Organizations: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base organizations.Organizations, instance string, requ // Create implements organizations.Organizations func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Organization) (created *organizations.Organization, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Find"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Find"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -150,10 +155,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -184,10 +189,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/references/middleware/telemetry_middleware.go b/pkg/references/middleware/telemetry_middleware.go index 2af52982..1d93caac 100644 --- a/pkg/references/middleware/telemetry_middleware.go +++ b/pkg/references/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base references.References, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base references.References, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ References: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base references.References, instance string, requestMet // 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -84,10 +89,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Publish"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Publish"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/roles/middleware/telemetry_middleware.go b/pkg/roles/middleware/telemetry_middleware.go index b80a9dc2..5365a18d 100644 --- a/pkg/roles/middleware/telemetry_middleware.go +++ b/pkg/roles/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base roles.Roles, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base roles.Roles, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Roles: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base roles.Roles, instance string, requestMetrics *metr // Create implements roles.Roles func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (created *roles.Role, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -80,10 +85,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -149,10 +154,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -183,10 +188,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/spaces/middleware/telemetry_middleware.go b/pkg/spaces/middleware/telemetry_middleware.go index c15fff13..9d7a4094 100644 --- a/pkg/spaces/middleware/telemetry_middleware.go +++ b/pkg/spaces/middleware/telemetry_middleware.go @@ -29,7 +29,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base spaces.Spaces, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base spaces.Spaces, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Spaces: base, _instance: instance, @@ -46,10 +51,10 @@ func TelemetryMiddleware(base spaces.Spaces, instance string, requestMetrics *me // AbortTransfer implements spaces.Spaces func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("AbortTransfer"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "AbortTransfer"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -79,10 +84,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -113,10 +118,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -146,10 +151,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -180,10 +185,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("List"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "List"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -214,10 +219,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("ListTransfers"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "ListTransfers"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -248,10 +253,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Move"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Move"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -282,10 +287,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Transfer"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Transfer"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -316,10 +321,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -349,10 +354,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("UpdateConfig"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "UpdateConfig"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/users/middleware/telemetry_middleware.go b/pkg/users/middleware/telemetry_middleware.go index 7edba72c..6d39a58d 100644 --- a/pkg/users/middleware/telemetry_middleware.go +++ b/pkg/users/middleware/telemetry_middleware.go @@ -30,7 +30,12 @@ type telemetryMiddleware struct { } // TelemetryMiddleware returns telemetryMiddleware -func TelemetryMiddleware(base users.Users, instance string, requestMetrics *metrics.RequestMetrics, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { +func TelemetryMiddleware(base users.Users, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) telemetryMiddleware { + requestMetrics, err := metrics.NewRequestMetrics(instance) + if err != nil { + panic(err) + } + d := telemetryMiddleware{ Users: base, _instance: instance, @@ -47,10 +52,10 @@ func TelemetryMiddleware(base users.Users, instance string, requestMetrics *metr // Create implements users.Users func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { - attributes := metricotel.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Create"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Create"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -81,10 +86,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Delete"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Delete"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -114,10 +119,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Find"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Find"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -150,10 +155,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Get"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Get"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -184,10 +189,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("GetByIdentity"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "GetByIdentity"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -218,10 +223,10 @@ 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.WithAttributes( - attribute.Key("service").String(_d.serviceName), - attribute.Key("method").String("Update"), - ) + attributes := metricotel.WithAttributeSet(attribute.NewSet( + attribute.String("service", _d.serviceName), + attribute.String("method", "Update"), + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) -- GitLab