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 <chelsea.e.mafrica@intel.com>
This commit is contained in:
Chelsea Mafrica 2021-08-26 15:13:34 -07:00
parent 8058e97212
commit 87de26bda3

View File

@ -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")