From a144bfdc34fdd2f4fb2cdc2dd06f1d96679b9563 Mon Sep 17 00:00:00 2001 From: ka3de Date: Thu, 21 Dec 2023 17:09:59 +0100 Subject: [PATCH] Override OTEL tracer Start() to include metadata 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. --- trace/trace.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/trace/trace.go b/trace/trace.go index fc6d97021..448748995 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -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