Skip to content

Commit

Permalink
hold onto otel tracer, fixed tracer name
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-asher committed Feb 9, 2024
1 parent 183c00b commit 7df4521
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lisp/x/profiler/opentelemetry_annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 7df4521

Please sign in to comment.