From 87de26bda31d0803a333749213c2e31ec3a992d3 Mon Sep 17 00:00:00 2001 From: Chelsea Mafrica Date: Thu, 26 Aug 2021 15:13:34 -0700 Subject: [PATCH] tracing: Modify Trace() to accept multiple tag maps The general Trace() function accepts one map as a set of tags. Modify it to accept multiple sets of tags so that additional ones can be added at Trace() and not as a subsequent call. Additionally, we should not iterate over the maps unless tracing tracing is enabled. Fixes #2512 Signed-off-by: Chelsea Mafrica --- src/runtime/pkg/katautils/katatrace/tracing.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runtime/pkg/katautils/katatrace/tracing.go b/src/runtime/pkg/katautils/katatrace/tracing.go index 395475a09..f7f5f40c3 100644 --- a/src/runtime/pkg/katautils/katatrace/tracing.go +++ b/src/runtime/pkg/katautils/katatrace/tracing.go @@ -129,7 +129,7 @@ func StopTracing(ctx context.Context) { // Trace creates a new tracing span based on the specified name and parent context. // It also accepts a logger to record nil context errors and a map of tracing tags. // Tracing tag keys and values are strings. -func Trace(parent context.Context, logger *logrus.Entry, name string, tags map[string]string) (otelTrace.Span, context.Context) { +func Trace(parent context.Context, logger *logrus.Entry, name string, tags ...map[string]string) (otelTrace.Span, context.Context) { if parent == nil { if logger == nil { logger = kataTraceLogger @@ -139,8 +139,13 @@ func Trace(parent context.Context, logger *logrus.Entry, name string, tags map[s } var otelTags []label.KeyValue - for k, v := range tags { - otelTags = append(otelTags, label.Key(k).String(v)) + // do not append tags if tracing is disabled + if tracing { + for _, tagSet := range tags { + for k, v := range tagSet { + otelTags = append(otelTags, label.Key(k).String(v)) + } + } } tracer := otel.Tracer("kata")