Skip to content

Commit

Permalink
Override OTEL tracer Start() to include metadata
Browse files Browse the repository at this point in the history
Modifies our tracer implementation to override the underlying OTEL's
tracer Start() method so the extra traces metadata set by the
K6_BROWSER_TRACES_METADATA environment variable is also including when
using the Start() method directly. Currently the Start() method is only
used when creating the root span for each iteration.
  • Loading branch information
ka3de committed Jan 9, 2024
1 parent a224e27 commit a144bfd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func NewTracer(tp k6lib.TracerProvider, metadata map[string]string, options ...t
}
}

// Start overrides the underlying OTEL tracer method to include the tracer metadata.
func (t *Tracer) Start(
ctx context.Context, spanName string, opts ...trace.SpanStartOption,
) (context.Context, trace.Span) {
opts = append(opts, trace.WithAttributes(t.metadata...))
return t.Tracer.Start(ctx, spanName, opts...)
}

// TraceAPICall adds a new span to the current liveSpan for the given targetID and returns it. It
// is the caller's responsibility to close the generated span.
// If there is not a liveSpan for the given targetID, the new span is created based on the given
Expand Down

0 comments on commit a144bfd

Please sign in to comment.