diff --git a/assets/templates/middleware/telemetry_account b/assets/templates/middleware/telemetry_account deleted file mode 100644 index 39bf058e8c6ee397cb9d0d10dd96d9c0a7c81af5..0000000000000000000000000000000000000000 --- a/assets/templates/middleware/telemetry_account +++ /dev/null @@ -1,78 +0,0 @@ -// source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry - -import ( - "context" - "time" - - "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - otelmetric "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/trace" -) - -{{ $decorator := (or .Vars.DecoratorName "telemetryMiddleware") }} -{{ $funcName := (or .Vars.FuncName ("TelemetryMiddleware")) }} - -// {{$decorator}} implements {{.Interface.Type}} interface instrumented with opentracing spans -type {{$decorator}} struct { - {{.Interface.Type}} - _instance string - requestMetrics *metrics.RequestMetrics - _spanDecorator func(span trace.Span, params, results map[string]interface{}) -} - -// {{$funcName}} returns {{$decorator}} -func {{$funcName}} (base {{.Interface.Type}}, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) {{$decorator}} { - requestMetrics, err := metrics.GetRequestMetrics() - if err != nil { - panic(err) - } - - d := {{$decorator}} { - {{.Interface.Name}}: base, - _instance: instance, - requestMetrics: requestMetrics, - } - - if len(spanDecorator) > 0 && spanDecorator[0] != nil { - d._spanDecorator = spanDecorator[0] - } - - return d -} - -{{range $method := .Interface.Methods}} - {{if $method.AcceptsContext}} - // {{$method.Name}} implements {{$.Interface.Type}} -func (_d {{$decorator}}) {{$method.Declaration}} { - attributes := otelmetric.WithAttributeSet(attribute.NewSet( - attribute.String("service", "{{ $.Interface.Name }}"), - attribute.String("method", "{{ $method.Name }}"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), - )) - - _d.requestMetrics.Total.Add(ctx, 1, attributes) - - start := time.Now() - ctx, _span := otel.Tracer(_d._instance).Start(ctx, "{{$.Interface.Name}}.{{$method.Name}}") - - defer func() { - _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - - if _d._spanDecorator != nil { - _d._spanDecorator(_span, {{$method.ParamsMap}}, {{$method.ResultsMap}}) - }{{- if $method.ReturnsError}} else if err != nil { - _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) - - _span.RecordError(err) - _span.SetAttributes(attribute.String("event", "error")) - _span.SetAttributes(attribute.String("message", err.Error())) - } - {{end}} - _span.End() - }() - {{$method.Pass (printf "_d.%s." $.Interface.Name) }} -} - {{end}} -{{end}} \ No newline at end of file diff --git a/assets/templates/middleware/telemetry_content b/assets/templates/middleware/telemetry_content deleted file mode 100644 index 8f3903c7c6368443d066d11fdffaece8c613af22..0000000000000000000000000000000000000000 --- a/assets/templates/middleware/telemetry_content +++ /dev/null @@ -1,130 +0,0 @@ -// source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry - -import ( - "context" - "time" - - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - otelmetric "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/trace" -) - -type SpaceGetter interface { - GetSpaceID() string -} - -{{ $decorator := (or .Vars.DecoratorName "telemetryMiddleware") }} -{{ $funcName := (or .Vars.FuncName ("TelemetryMiddleware")) }} - -// {{$decorator}} implements {{.Interface.Type}} interface instrumented with opentracing spans -type {{$decorator}} struct { - {{.Interface.Type}} - _instance string - requestMetrics *metrics.RequestMetrics - _spanDecorator func(span trace.Span, params, results map[string]interface{}) -} - -// {{$funcName}} returns {{$decorator}} -func {{$funcName}} (base {{.Interface.Type}}, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) {{$decorator}} { - requestMetrics, err := metrics.GetRequestMetrics() - if err != nil { - panic(err) - } - - d := {{$decorator}} { - {{.Interface.Name}}: base, - _instance: instance, - requestMetrics: requestMetrics, - } - - if len(spanDecorator) > 0 && spanDecorator[0] != nil { - d._spanDecorator = spanDecorator[0] - } - - return d -} -{{- $paramsList := list -}} -{{range $method := .Interface.Methods}} - {{if $method.AcceptsContext}} - {{- $paramsList = list -}} - {{- $paramsList = append $paramsList $method.ParamsNames -}} - {{- $paramsList = append $paramsList $method.ResultsNames -}} - // {{$method.Name}} implements {{$.Interface.Type}} -func (_d {{$decorator}}) {{$method.Declaration}} { - {{ $spaceID := "" }} - {{- range $param := $method.Params -}} - {{- if (eq $param.Name "spaceId") -}} - {{- $spaceID = "spaceId" -}} - {{- end -}} - {{- end -}} - var att = []attribute.KeyValue{ - attribute.String("service", "{{ $.Interface.Name }}"), - attribute.String("method", "{{ $method.Name }}"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) - - _d.requestMetrics.Total.Add(ctx, 1, attributes) - - start := time.Now() - ctx, _span := otel.Tracer(_d._instance).Start(ctx, "{{$.Interface.Name}}.{{$method.Name}}") - - defer func() { - _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - - var spID string - {{- if (eq $spaceID "") -}} - {{- $l := len $paramsList }} - vv := []interface{}{ - {{- range $i, $p := $paramsList | toStrings }} - {{- if (eq $i $l) }} - {{- $p }} - {{- else }} - {{- $p }}, - {{- end -}} - {{- end -}} - } - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - {{- else }} - spID = spaceId - {{- end }} - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - - if _d._spanDecorator != nil { - _d._spanDecorator(_span, {{$method.ParamsMap}}, {{$method.ResultsMap}}) - }{{- if $method.ReturnsError}} else if err != nil { - _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) - - _span.RecordError(err) - _span.SetAttributes(attribute.String("event", "error")) - _span.SetAttributes(attribute.String("message", err.Error())) - } - {{end}} - _span.End() - }() - {{$method.Pass (printf "_d.%s." $.Interface.Name) }} -} - {{end}} -{{end}} \ No newline at end of file diff --git a/images/middleware/telemetry_middleware.go b/images/middleware/telemetry_middleware.go index b34c1f618343df92afb3ea9d7a353851340a3704..72d38c2e1d91813383116398e5c41b9bb93004f4 100644 --- a/images/middleware/telemetry_middleware.go +++ b/images/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../assets/templates/middleware/telemetry +// template: ..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/images -i Images -t ../../assets/templates/middleware/telemetry -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/images -i Images -t ..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry diff --git a/pkg/clients/client.go b/pkg/clients/client.go index 447c523aaf5ae8692421e85567973f407007561a..6c4c6735b8ec91f226ba5306b2649252390ffc67 100644 --- a/pkg/clients/client.go +++ b/pkg/clients/client.go @@ -50,10 +50,6 @@ func (c Client) GetID() string { return c.ID } -func (c Client) GetSpaceID() string { - return c.SpaceID -} - func (c *Client) SetDisabled(b bool) *Client { c.Disabled = &b return c diff --git a/pkg/clients/middleware/telemetry_middleware.go b/pkg/clients/middleware/telemetry_middleware.go index 284aac9522d9993c517ef6b49d448476c42fa9aa..22c604f2d5be413681ccdb933eb5c33a61517cc6 100644 --- a/pkg/clients/middleware/telemetry_middleware.go +++ b/pkg/clients/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/clients -i Clients -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/clients -i Clients -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/clients" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -22,10 +20,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements clients.Clients interface instrumented with opentracing spans type telemetryMiddleware struct { clients.Clients @@ -56,12 +50,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -71,30 +63,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, client *clients.Client defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, client, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -116,12 +84,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -131,21 +97,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -167,12 +118,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "Enable"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -182,21 +131,6 @@ func (_d telemetryMiddleware) Enable(ctx context.Context, spaceId string, id str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -219,12 +153,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -234,21 +166,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -271,12 +188,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "GetBy"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -286,21 +201,6 @@ func (_d telemetryMiddleware) GetBy(ctx context.Context, spaceId string, params defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -323,12 +223,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -338,21 +236,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (clients defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -374,12 +257,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Clients"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -389,30 +270,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, client *clients.Client defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, client, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/collaborators/collaborator.go b/pkg/collaborators/collaborator.go index b3406960b899f66ce498358d8a3199eb223e9de0..5fe1b481c231568af13b9c9e827eede723312576 100644 --- a/pkg/collaborators/collaborator.go +++ b/pkg/collaborators/collaborator.go @@ -13,7 +13,3 @@ func (c Collaborator) Clone() *Collaborator { Role: c.Role, } } - -func (c *Collaborator) GetSpaceID() string { - return c.SpaceID -} diff --git a/pkg/collaborators/middleware/telemetry_middleware.go b/pkg/collaborators/middleware/telemetry_middleware.go index 310eb2b52a6f03de2e9842fd587048f98ace25a2..cd95016628ed34da1c6fdd5c951a14c766a8cabc 100644 --- a/pkg/collaborators/middleware/telemetry_middleware.go +++ b/pkg/collaborators/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/collaborators -i Collaborators -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/collaborators -i Collaborators -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collaborators" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -22,10 +20,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements collaborators.Collaborators interface instrumented with opentracing spans type telemetryMiddleware struct { collaborators.Collaborators @@ -56,12 +50,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collaborators"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -71,21 +63,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, subject s defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -108,12 +85,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collaborators"), attribute.String("method", "ListCollaborators"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -123,21 +98,6 @@ func (_d telemetryMiddleware) ListCollaborators(ctx context.Context, spaceId str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -159,12 +119,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collaborators"), attribute.String("method", "ListSpaces"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -174,30 +132,6 @@ func (_d telemetryMiddleware) ListSpaces(ctx context.Context, subject string) (s defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, subject, spaces, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -219,12 +153,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collaborators"), attribute.String("method", "Remove"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -234,21 +166,6 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, spaceId string, subjec defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -270,12 +187,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collaborators"), attribute.String("method", "Set"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -285,21 +200,6 @@ func (_d telemetryMiddleware) Set(ctx context.Context, spaceId string, subject s defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/collections/collection.go b/pkg/collections/collection.go index 2baeffc6b3f87b90c281aebd5dae85c57d93a5cd..b5d2418aac40332c99b08b31a5df128007e1b7a6 100644 --- a/pkg/collections/collection.go +++ b/pkg/collections/collection.go @@ -97,10 +97,6 @@ func (c Collection) GetID() string { return c.ID } -func (c Collection) GetSpaceID() string { - return c.SpaceID -} - // Equal Ñравнивает две коллекции, за иÑключением Schema, Access, StateInfo и Config func (c Collection) Equal(other *Collection) bool { if c.ID != other.ID || diff --git a/pkg/collections/middleware/telemetry_middleware.go b/pkg/collections/middleware/telemetry_middleware.go index 1651bef49bf94a8ccfd3bc8aa6ae5323c96b60cb..306570dba01ac1d7faaf193d92f97820369a6ad2 100644 --- a/pkg/collections/middleware/telemetry_middleware.go +++ b/pkg/collections/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/collections -i Collections -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/collections -i Collections -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -23,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements collections.Collections interface instrumented with opentracing spans type telemetryMiddleware struct { collections.Collections @@ -57,12 +51,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -72,30 +64,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, collection, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -117,12 +85,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -132,21 +98,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -169,12 +120,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -184,21 +133,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -223,12 +157,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -238,21 +170,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -276,12 +193,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "SetSchema"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -291,21 +206,6 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -329,12 +229,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "SetState"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -344,21 +242,6 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envI defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -382,12 +265,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Collections"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -397,30 +278,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, coll *collections.Coll defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, coll, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/delivery/middleware/telemetry_middleware.go b/pkg/delivery/middleware/telemetry_middleware.go index d8ad462e8a7a50ff9a216c70fa2fbee46fc4c1ca..05a017300c0b2d60c0cc03df333c62365babffa6 100644 --- a/pkg/delivery/middleware/telemetry_middleware.go +++ b/pkg/delivery/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/delivery -i Delivery -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/delivery -i Delivery -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/delivery" "git.perx.ru/perxis/perxis-go/pkg/environments" @@ -26,10 +24,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements delivery.Delivery interface instrumented with opentracing spans type telemetryMiddleware struct { delivery.Delivery @@ -60,12 +54,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "Aggregate"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -75,21 +67,6 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -115,12 +92,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "FindItems"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -130,21 +105,6 @@ func (_d telemetryMiddleware) FindItems(ctx context.Context, spaceId string, env defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -171,12 +131,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "GetCollection"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -186,21 +144,6 @@ func (_d telemetryMiddleware) GetCollection(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -224,12 +167,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "GetEnvironment"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -239,21 +180,6 @@ func (_d telemetryMiddleware) GetEnvironment(ctx context.Context, spaceId string defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -276,12 +202,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "GetItem"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -291,21 +215,6 @@ func (_d telemetryMiddleware) GetItem(ctx context.Context, spaceId string, envId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -331,12 +240,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "ListCollections"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -346,21 +253,6 @@ func (_d telemetryMiddleware) ListCollections(ctx context.Context, spaceId strin defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -383,12 +275,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "ListEnvironments"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -398,21 +288,6 @@ func (_d telemetryMiddleware) ListEnvironments(ctx context.Context, spaceId stri defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -434,12 +309,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Delivery"), attribute.String("method", "ListLocales"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -449,21 +322,6 @@ func (_d telemetryMiddleware) ListLocales(ctx context.Context, spaceId string) ( defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/environments/environment.go b/pkg/environments/environment.go index 6ccfc2558e90e14c94925bdd29f56df71aac22b9..3e0f7bb62a0be1d2fbef334322a6cb315060af8a 100644 --- a/pkg/environments/environment.go +++ b/pkg/environments/environment.go @@ -104,7 +104,3 @@ func (e Environment) Clone() *Environment { return clone } - -func (e Environment) GetSpaceID() string { - return e.SpaceID -} diff --git a/pkg/environments/middleware/telemetry_middleware.go b/pkg/environments/middleware/telemetry_middleware.go index bd5388cee54376590c62e378367fc2aaedae7eb1..95b50dbc590f134386747a2fb4810455e7f2a800 100644 --- a/pkg/environments/middleware/telemetry_middleware.go +++ b/pkg/environments/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/environments -i Environments -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/environments -i Environments -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/environments" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -22,10 +20,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements environments.Environments interface instrumented with opentracing spans type telemetryMiddleware struct { environments.Environments @@ -56,12 +50,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -71,30 +63,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Envi defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, env, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -116,12 +84,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -131,21 +97,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -167,12 +118,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -182,21 +131,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -219,12 +153,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -234,21 +166,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (envs [] defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -270,12 +187,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "Migrate"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -285,21 +200,6 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -322,12 +222,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "RemoveAlias"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -337,21 +235,6 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -374,12 +257,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "SetAlias"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -389,21 +270,6 @@ func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envI defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -426,12 +292,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Environments"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -441,30 +305,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, env *environments.Envi defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, env, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/files/middleware/telemetry_middleware.go b/pkg/files/middleware/telemetry_middleware.go index 386ad3eb42845cf0291aee46e1ceaf04fc351ea3..bed97ea15eba2acd026249d698195835ee6a9db1 100644 --- a/pkg/files/middleware/telemetry_middleware.go +++ b/pkg/files/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/files -i Files -t ../../../assets/templates/middleware/telemetry -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/files -i Files -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry diff --git a/pkg/invitations/invitation.go b/pkg/invitations/invitation.go index 86d0db29a4d77b0eb7e7533b706d4a299fbed388..a5b91ed006693748deb71877b8e555e485b0c6c8 100644 --- a/pkg/invitations/invitation.go +++ b/pkg/invitations/invitation.go @@ -27,7 +27,3 @@ func (i Invitation) Clone() *Invitation { ValidUntil: i.ValidUntil, } } - -func (i Invitation) GetSpaceID() string { - return i.SpaceID -} diff --git a/pkg/invitations/middleware/telemetry_middleware.go b/pkg/invitations/middleware/telemetry_middleware.go index b46faa4a843e29e4155523672b3f4d0d46e52961..44b7d2683137884f330946cce8d39a0eb3617d15 100644 --- a/pkg/invitations/middleware/telemetry_middleware.go +++ b/pkg/invitations/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/invitations -i Invitations -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/invitations -i Invitations -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/invitations" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -23,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements invitations.Invitations interface instrumented with opentracing spans type telemetryMiddleware struct { invitations.Invitations @@ -57,12 +51,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Invitations"), attribute.String("method", "Accept"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -72,30 +64,6 @@ func (_d telemetryMiddleware) Accept(ctx context.Context, invitationId string, u defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, invitationId, userId, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -117,12 +85,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Invitations"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -132,30 +98,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, invitation *invitation defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, invitation, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -177,12 +119,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Invitations"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -192,30 +132,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, invitationId string) ( defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, invitationId, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -236,12 +152,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Invitations"), attribute.String("method", "Find"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -251,30 +165,6 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *invitations.Filt defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, filter, opts, invitations, total, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -298,12 +188,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Invitations"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -313,30 +201,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, invitationId string) (inv defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, invitationId, invitation, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/items/item.go b/pkg/items/item.go index fa1bc0848f8422b7ac8ce5410ca0b82c902370ab..78e33babe8336f9cffce5d1ff241713f5d573c13 100644 --- a/pkg/items/item.go +++ b/pkg/items/item.go @@ -150,10 +150,6 @@ func (i *Item) GetID() string { return i.ID } -func (i *Item) GetSpaceID() string { - return i.SpaceID -} - func (i *Item) Clone() *Item { itm := *i itm.Data = data.CloneMap(i.Data) diff --git a/pkg/items/middleware/telemetry_middleware.go b/pkg/items/middleware/telemetry_middleware.go index dc9d8d457692c3b3b7dac6e5bca98e6b0365e57a..98891f9f4f957ffe12626150c58e8bb7df67389a 100644 --- a/pkg/items/middleware/telemetry_middleware.go +++ b/pkg/items/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/items -i Items -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/items -i Items -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -23,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements items.Items interface instrumented with opentracing spans type telemetryMiddleware struct { items.Items @@ -57,12 +51,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Aggregate"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -72,21 +64,6 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -112,12 +89,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "AggregatePublished"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -127,21 +102,6 @@ func (_d telemetryMiddleware) AggregatePublished(ctx context.Context, spaceId st defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -167,12 +127,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Archive"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -182,30 +140,6 @@ func (_d telemetryMiddleware) Archive(ctx context.Context, item *items.Item, opt defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -227,12 +161,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -242,30 +174,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, item *items.Item, opts defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, opts, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -288,12 +196,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -303,30 +209,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, item *items.Item, opti defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -348,12 +230,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Find"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -363,21 +243,6 @@ func (_d telemetryMiddleware) Find(ctx context.Context, spaceId string, envId st defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -404,12 +269,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "FindArchived"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -419,21 +282,6 @@ func (_d telemetryMiddleware) FindArchived(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -460,12 +308,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "FindPublished"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -475,21 +321,6 @@ func (_d telemetryMiddleware) FindPublished(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -516,12 +347,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -531,21 +360,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -571,12 +385,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "GetPublished"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -586,21 +398,6 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -626,12 +423,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "GetRevision"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -641,21 +436,6 @@ func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, e defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -682,12 +462,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Introspect"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -697,30 +475,6 @@ func (_d telemetryMiddleware) Introspect(ctx context.Context, item *items.Item, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, opts, itm, sch, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -744,12 +498,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "ListRevisions"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -759,21 +511,6 @@ func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -799,12 +536,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Publish"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -814,30 +549,6 @@ func (_d telemetryMiddleware) Publish(ctx context.Context, item *items.Item, opt defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -859,12 +570,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Unarchive"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -874,30 +583,6 @@ func (_d telemetryMiddleware) Unarchive(ctx context.Context, item *items.Item, o defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -919,12 +604,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Undelete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -934,30 +617,6 @@ func (_d telemetryMiddleware) Undelete(ctx context.Context, item *items.Item, op defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -979,12 +638,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Unpublish"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -994,30 +651,6 @@ func (_d telemetryMiddleware) Unpublish(ctx context.Context, item *items.Item, o defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -1039,12 +672,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Items"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -1054,30 +685,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, item *items.Item, opti defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, item, options, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/locales/locale.go b/pkg/locales/locale.go index 80cd2d60c884951206ccb3aad5113f0a369b68bf..e0e32616ee4bd526c7d25c9cbab740e196529328 100644 --- a/pkg/locales/locale.go +++ b/pkg/locales/locale.go @@ -55,10 +55,6 @@ func (locale *Locale) Key() string { return locale.ID } -func (locale *Locale) GetSpaceID() string { - return locale.SpaceID -} - // Возвращает Ñзык локали, например "en", "ru" func (locale *Locale) GetLanguage() string { lang, err := language.Parse(locale.Code) diff --git a/pkg/locales/middleware/telemetry_middleware.go b/pkg/locales/middleware/telemetry_middleware.go index b1196849ba1f26ed7f5b37185748418e17b114ec..98fe346ea000409be27bfd21fccc6723ed09851b 100644 --- a/pkg/locales/middleware/telemetry_middleware.go +++ b/pkg/locales/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ../../../assets/templates/middleware/telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/locales -i Locales -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/locales -i Locales -t ../../../assets/templates/middleware/telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/locales" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -22,10 +20,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements locales.Locales interface instrumented with opentracing spans type telemetryMiddleware struct { locales.Locales @@ -56,12 +50,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Locales"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -71,30 +63,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, locale, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -116,12 +84,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Locales"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -131,21 +97,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, locale defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -167,12 +118,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Locales"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -182,21 +131,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (locales defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -218,12 +152,10 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (locales // Update implements locales.Locales func (_d telemetryMiddleware) Update(ctx context.Context, locale *locales.Locale) (err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Locales"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -233,30 +165,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, locale *locales.Locale defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, locale, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/members/middleware/middleware.go b/pkg/members/middleware/middleware.go index bb491623865e21496adedb1e91987bc2205a3ce4..04626790010ac2da99f00e8501d1c4186683e6b7 100644 --- a/pkg/members/middleware/middleware.go +++ b/pkg/members/middleware/middleware.go @@ -21,7 +21,7 @@ func WithLog(s members.Members, logger *zap.Logger, log_access bool) members.Mem if log_access { s = AccessLoggingMiddleware(logger)(s) } - s = ErrorLoggingMiddleware(logger)(s) + s = LoggingMiddleware(logger)(s) s = RecoveringMiddleware(logger)(s) return s diff --git a/pkg/members/middleware/telemetry_middleware.go b/pkg/members/middleware/telemetry_middleware.go index 682679586d754eadc0682624847c5ee91cdd9b78..6193a4bacb41dcea61a1384e939bcdb2785f5e8a 100644 --- a/pkg/members/middleware/telemetry_middleware.go +++ b/pkg/members/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_account +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/members -i Members -t ../../../assets/templates/middleware/telemetry_account -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/members -i Members -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,7 +12,6 @@ import ( "context" "time" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/members" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -54,7 +53,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string, userId stri attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "Get"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -90,7 +88,6 @@ func (_d telemetryMiddleware) ListMembers(ctx context.Context, orgId string) (me attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "ListMembers"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -125,7 +122,6 @@ func (_d telemetryMiddleware) ListOrganizations(ctx context.Context, userId stri attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "ListOrganizations"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -160,7 +156,6 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, orgId string, userId s attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "Remove"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -195,7 +190,6 @@ func (_d telemetryMiddleware) RemoveAll(ctx context.Context, orgId string) (err attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "RemoveAll"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -229,7 +223,6 @@ func (_d telemetryMiddleware) Set(ctx context.Context, orgId string, userId stri attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Members"), attribute.String("method", "Set"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/organizations/middleware/telemetry_middleware.go b/pkg/organizations/middleware/telemetry_middleware.go index 6d35569ece650d7c05d49bdcb1644c4c7d4eeb46..d728b1f10f4ba303b6469d3a1b8bf63cb24a7283 100644 --- a/pkg/organizations/middleware/telemetry_middleware.go +++ b/pkg/organizations/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_account +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/organizations -i Organizations -t ../../../assets/templates/middleware/telemetry_account -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/organizations -i Organizations -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,7 +12,6 @@ import ( "context" "time" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/organizations" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -55,7 +54,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Org attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Organizations"), attribute.String("method", "Create"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -90,7 +88,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err err attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Organizations"), attribute.String("method", "Delete"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -124,7 +121,6 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *organizations.Fi attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Organizations"), attribute.String("method", "Find"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -161,7 +157,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organ attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Organizations"), attribute.String("method", "Get"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -196,7 +191,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, org *organizations.Org attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Organizations"), attribute.String("method", "Update"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) diff --git a/pkg/references/middleware/telemetry_middleware.go b/pkg/references/middleware/telemetry_middleware.go index c4203bfee908aab5de851bdd5ab0b14738a180dc..71c51698bd9c015fdefd24e79b41ddcacda09eb2 100644 --- a/pkg/references/middleware/telemetry_middleware.go +++ b/pkg/references/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ../../../assets/templates/middleware/telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/references -i References -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/references -i References -t ../../../assets/templates/middleware/telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/references" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -23,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements references.References interface instrumented with opentracing spans type telemetryMiddleware struct { references.References @@ -57,12 +51,10 @@ 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, options ...*references.GetOptions) (items []*items.Item, notfound []*references.Reference, err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "References"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -72,21 +64,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -112,12 +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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "References"), attribute.String("method", "Publish"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -127,21 +102,6 @@ func (_d telemetryMiddleware) Publish(ctx context.Context, spaceId string, envId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/roles/middleware/middleware.go b/pkg/roles/middleware/middleware.go index aaeb2da895d5aa71768e577315e549daa6a247c4..299199a40432f486d1020bb803f5bff18a95428e 100644 --- a/pkg/roles/middleware/middleware.go +++ b/pkg/roles/middleware/middleware.go @@ -21,7 +21,7 @@ func WithLog(s roles.Roles, logger *zap.Logger, log_access bool) roles.Roles { if log_access { s = AccessLoggingMiddleware(logger)(s) } - s = ErrorLoggingMiddleware(logger)(s) + s = LoggingMiddleware(logger)(s) s = RecoveringMiddleware(logger)(s) return s diff --git a/pkg/roles/middleware/telemetry_middleware.go b/pkg/roles/middleware/telemetry_middleware.go index 65772b99020016d810994a9ec7341b54929e373f..5d9d5e35cee66af5e24fb5888d52907ce35aadde 100644 --- a/pkg/roles/middleware/telemetry_middleware.go +++ b/pkg/roles/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/roles -i Roles -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/roles -i Roles -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/roles" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" @@ -22,10 +20,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements roles.Roles interface instrumented with opentracing spans type telemetryMiddleware struct { roles.Roles @@ -56,12 +50,10 @@ 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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Roles"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -71,30 +63,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (cre defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, role, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -116,12 +84,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Roles"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -131,21 +97,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -167,12 +118,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Roles"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -182,21 +131,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId st defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -219,12 +153,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Roles"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -234,21 +166,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (roles [ defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -270,12 +187,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Roles"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -285,30 +200,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, role *roles.Role) (err defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, role, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/roles/role.go b/pkg/roles/role.go index 81feb1e909f15d40a918309a25add9c420e25b35..76520f8fbf353c027ae782efb1bf79a1bfa453f5 100644 --- a/pkg/roles/role.go +++ b/pkg/roles/role.go @@ -40,10 +40,6 @@ func (r Role) GetID() string { return r.ID } -func (r Role) GetSpaceID() string { - return r.SpaceID -} - func (r Role) Clone() *Role { return &Role{ ID: r.ID, diff --git a/pkg/spaces/middleware/access_logging_middleware.go b/pkg/spaces/middleware/access_logging_middleware.go index d155ee1f0d95daad6b29c5961604cdc8b466fcd9..9596d7d4fc2daa611a0db631eef56fe6d5531488 100644 --- a/pkg/spaces/middleware/access_logging_middleware.go +++ b/pkg/spaces/middleware/access_logging_middleware.go @@ -184,25 +184,6 @@ func (m *accessLoggingMiddleware) Move(ctx context.Context, spaceID string, orgI return err } -func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { - begin := time.Now() - - m.logger.Debug("SetState.Request", - zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceID", spaceID), - zap.Reflect("state", state), - ) - - err = m.next.SetState(ctx, spaceID, state) - - m.logger.Debug("SetState.Response", - zap.Duration("time", time.Since(begin)), - zap.Error(err), - ) - - return err -} - func (m *accessLoggingMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { begin := time.Now() @@ -258,3 +239,22 @@ func (m *accessLoggingMiddleware) UpdateConfig(ctx context.Context, spaceId stri return err } + +func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { + begin := time.Now() + + m.logger.Debug("SetState.Request", + zap.Reflect("principal", auth.GetPrincipal(ctx)), + zap.Reflect("spaceID", spaceID), + zap.Reflect("state", state), + ) + + err = m.next.SetState(ctx, spaceID, state) + + m.logger.Debug("SetState.Response", + zap.Duration("time", time.Since(begin)), + zap.Error(err), + ) + + return err +} diff --git a/pkg/spaces/middleware/telemetry_middleware.go b/pkg/spaces/middleware/telemetry_middleware.go index f3d69b57767fad4e700780f48aa60e33dc74b340..e9623692afe644e58cb1b406b4b06a3208edc710 100644 --- a/pkg/spaces/middleware/telemetry_middleware.go +++ b/pkg/spaces/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_content +// template: ../../../assets/templates/middleware/telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/spaces -i Spaces -t ../../../assets/templates/middleware/telemetry_content -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/spaces -i Spaces -t ../../../assets/templates/middleware/telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,8 +12,6 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/spaces" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -23,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -type SpaceGetter interface { - GetSpaceID() string -} - // telemetryMiddleware implements spaces.Spaces interface instrumented with opentracing spans type telemetryMiddleware struct { spaces.Spaces @@ -57,12 +51,10 @@ func TelemetryMiddleware(base spaces.Spaces, instance string, spanDecorator ...f // AbortTransfer implements spaces.Spaces func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "AbortTransfer"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -72,30 +64,6 @@ func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, spaceID, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -116,12 +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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Create"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -131,30 +97,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, space *spaces.Space) ( defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, space, created, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -176,12 +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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Delete"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -191,21 +131,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err e defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -226,12 +151,10 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err e // Find implements spaces.Spaces func (_d telemetryMiddleware) Find(ctx context.Context, filter *spaces.Filter, fo *options.FindOptions) (spaces []*spaces.Space, total int, err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Find"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -241,30 +164,6 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *spaces.Filter, f defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, filter, fo, spaces, total, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -288,12 +187,10 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *spaces.Filter, f // Get implements spaces.Spaces func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Get"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -303,21 +200,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *s defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -339,12 +221,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "List"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -354,30 +234,6 @@ func (_d telemetryMiddleware) List(ctx context.Context, orgId string) (spaces [] defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, orgId, spaces, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -399,12 +255,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "ListTransfers"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -414,30 +268,6 @@ func (_d telemetryMiddleware) ListTransfers(ctx context.Context, orgID string) ( defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, orgID, spaces, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -459,12 +289,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Move"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -474,30 +302,6 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, spaceID, orgID, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -519,12 +323,10 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st // SetState implements spaces.Spaces func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "SetState"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -534,30 +336,6 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, spaceID, state, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -579,12 +357,10 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat // Transfer implements spaces.Spaces func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Transfer"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -594,30 +370,6 @@ func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, tran defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, spaceID, transferToOrg, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -639,12 +391,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "Update"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -654,30 +404,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, space *spaces.Space) ( defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - vv := []interface{}{ctx, space, err} - for _, v := range vv { - if v == nil { - continue - } - if sg, ok := v.(SpaceGetter); ok { - spID = sg.GetSpaceID() - break - } - } - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, @@ -698,12 +424,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) { - var att = []attribute.KeyValue{ + attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Spaces"), attribute.String("method", "UpdateConfig"), - } - - attributes := otelmetric.WithAttributeSet(attribute.NewSet(att...)) + )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -713,21 +437,6 @@ func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, spaceId string, defer func() { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - var spID string - spID = spaceId - if spID != "" { - principal := auth.GetPrincipal(ctx) - if accessor, ok := principal.(auth.SpaceAccessor); ok { - principal = accessor.Space(spID) - } - caller, _ := oid.NewObjectId(principal) - - att = append(att, attribute.String("spaceID", spID)) - att = append(att, attribute.String("caller", caller.String())) - } - - _d.requestMetrics.Total.Add(ctx, 1, otelmetric.WithAttributeSet(attribute.NewSet(att...))) - if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, diff --git a/pkg/spaces/space.go b/pkg/spaces/space.go index f4c5f4aba36c88695362d748073799d8e51f976e..baa44124b6830aa8c4f666f0300661952eadbc9d 100644 --- a/pkg/spaces/space.go +++ b/pkg/spaces/space.go @@ -88,7 +88,3 @@ type StateInfo struct { func (s Space) Clone() *Space { return &s } - -func (s Space) GetSpaceID() string { - return s.ID -} diff --git a/pkg/users/middleware/telemetry_middleware.go b/pkg/users/middleware/telemetry_middleware.go index d508595b5ff0a9cebf307008338eb708d601099c..698b4f6b4f2928e5f466e7855defa4c2df96ef36 100644 --- a/pkg/users/middleware/telemetry_middleware.go +++ b/pkg/users/middleware/telemetry_middleware.go @@ -1,10 +1,10 @@ // Code generated by gowrap. DO NOT EDIT. -// template: ../../../assets/templates/middleware/telemetry_account +// template: ..\..\..\assets\templates\middleware\telemetry // gowrap: http://github.com/hexdigest/gowrap package middleware -//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/users -i Users -t ../../../assets/templates/middleware/telemetry_account -o telemetry_middleware.go -l "" +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/users -i Users -t ..\..\..\assets\templates\middleware\telemetry -o telemetry_middleware.go -l "" // source template: https://github.com/hexdigest/gowrap/blob/master/templates/opentelemetry @@ -12,7 +12,6 @@ import ( "context" "time" - "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "git.perx.ru/perxis/perxis-go/pkg/users" @@ -55,7 +54,6 @@ func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (u attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "Create"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -90,7 +88,6 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err er attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "Delete"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -124,7 +121,6 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *users.Filter, op attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "Find"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -161,7 +157,6 @@ func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *use attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "Get"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -196,7 +191,6 @@ func (_d telemetryMiddleware) GetByIdentity(ctx context.Context, identity string attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "GetByIdentity"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes) @@ -231,7 +225,6 @@ func (_d telemetryMiddleware) Update(ctx context.Context, update *users.User) (e attributes := otelmetric.WithAttributeSet(attribute.NewSet( attribute.String("service", "Users"), attribute.String("method", "Update"), - attribute.String("principal", auth.GetPrincipal(ctx).GetID(ctx)), )) _d.requestMetrics.Total.Add(ctx, 1, attributes)