diff --git a/internal/metrics/otelmetrics/factory.go b/internal/metrics/otelmetrics/factory.go index ab846c2e43f..6d76dbeb8b8 100644 --- a/internal/metrics/otelmetrics/factory.go +++ b/internal/metrics/otelmetrics/factory.go @@ -1,9 +1,13 @@ package otelmetrics import ( - "github.com/jaegertracing/jaeger/pkg/metrics" + "context" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" + + "github.com/jaegertracing/jaeger/pkg/metrics" ) type otelFactory struct{} @@ -26,8 +30,9 @@ func (f *otelFactory) Counter(opts metrics.Options) metrics.Counter { attributeSet := attribute.NewSet(attributes...) return &otelCounter{ - counter: counter, - attributeSet: attributeSet, + counter: counter, + fixedCtx: context.Background(), + option: metric.WithAttributeSet(attributeSet), } } diff --git a/internal/metrics/otelmetrics/otelCounter.go b/internal/metrics/otelmetrics/otelCounter.go index 67a41b36273..c66e41c2bdf 100644 --- a/internal/metrics/otelmetrics/otelCounter.go +++ b/internal/metrics/otelmetrics/otelCounter.go @@ -3,15 +3,15 @@ package otelmetrics import ( "context" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" ) type otelCounter struct { - counter metric.Int64Counter - attributeSet attribute.Set + counter metric.Int64Counter + fixedCtx context.Context + option metric.AddOption } func (c *otelCounter) Inc(value int64) { - c.counter.Add(context.Background(), value, metric.WithAttributeSet(c.attributeSet)) + c.counter.Add(c.fixedCtx, value, c.option) }