diff --git a/lisp/x/profiler/opentelemetry_annotator.go b/lisp/x/profiler/opentelemetry_annotator.go index f23775e..b8d1aa1 100644 --- a/lisp/x/profiler/opentelemetry_annotator.go +++ b/lisp/x/profiler/opentelemetry_annotator.go @@ -11,17 +11,13 @@ import ( "go.opentelemetry.io/otel/trace" ) -const ( - // ContextOpenTelemetryTracerKey looks up a parent tracer name from a context key. - ContextOpenTelemetryTracerKey = "otelParentTracer" -) - var _ lisp.Profiler = &otelAnnotator{} type otelAnnotator struct { profiler currentContext context.Context currentSpan trace.Span + tracer trace.Tracer } func NewOpenTelemetryAnnotator(runtime *lisp.Runtime, parentContext context.Context, opts ...Option) *otelAnnotator { @@ -30,6 +26,7 @@ func NewOpenTelemetryAnnotator(runtime *lisp.Runtime, parentContext context.Cont runtime: runtime, }, currentContext: parentContext, + tracer: otel.GetTracerProvider().Tracer("elps"), } p.profiler.applyConfigs(opts...) return p @@ -50,21 +47,13 @@ func (p *otelAnnotator) Complete() error { return nil } -func contextTracer(ctx context.Context) trace.Tracer { - tracerName, ok := ctx.Value(ContextOpenTelemetryTracerKey).(string) - if !ok { - tracerName = "elps" - } - return otel.GetTracerProvider().Tracer(tracerName) -} - func (p *otelAnnotator) Start(fun *lisp.LVal) func() { if p.skipTrace(fun) { return func() {} } oldContext := p.currentContext prettyLabel, funName := p.prettyFunName(fun) - p.currentContext, p.currentSpan = contextTracer(p.currentContext).Start(p.currentContext, prettyLabel) + p.currentContext, p.currentSpan = p.tracer.Start(p.currentContext, prettyLabel) p.addCodeAttributes(fun, funName) return func() { p.currentSpan.End()