mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
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:
parent
8058e97212
commit
87de26bda3
@ -129,7 +129,7 @@ func StopTracing(ctx context.Context) {
|
|||||||
// Trace creates a new tracing span based on the specified name and parent 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.
|
// It also accepts a logger to record nil context errors and a map of tracing tags.
|
||||||
// Tracing tag keys and values are strings.
|
// 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 parent == nil {
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
logger = kataTraceLogger
|
logger = kataTraceLogger
|
||||||
@ -139,9 +139,14 @@ func Trace(parent context.Context, logger *logrus.Entry, name string, tags map[s
|
|||||||
}
|
}
|
||||||
|
|
||||||
var otelTags []label.KeyValue
|
var otelTags []label.KeyValue
|
||||||
for k, v := range tags {
|
// 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))
|
otelTags = append(otelTags, label.Key(k).String(v))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tracer := otel.Tracer("kata")
|
tracer := otel.Tracer("kata")
|
||||||
ctx, span := tracer.Start(parent, name, otelTrace.WithAttributes(otelTags...))
|
ctx, span := tracer.Start(parent, name, otelTrace.WithAttributes(otelTags...))
|
||||||
|
Loading…
Reference in New Issue
Block a user