Skip to content

Commit

Permalink
tracing: Hide trace messages unless tracing enabled
Browse files Browse the repository at this point in the history
Don't log trace-related messages unless tracing is actually enabled. If
tracing is not enabled, trace spans are still created, but the tracer is
a NOP. However, this is an implementation detail the user does not need
to be aware of so hide trace logs unless the user has enabled tracing
explicitly.

Fixes kata-containers#482.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Mar 15, 2019
1 parent 13347ed commit 6bd0f7c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func setupTracing(rootSpanName string) (opentracing.Span, context.Context, error
span.SetTag("source", "agent")
span.SetTag("root-span", "true")

agentLog.Debugf("created root span %v", span)
// See comment in trace().
if tracing {
agentLog.Debugf("created root span %v", span)
}

// Associate the root span with the context
ctx = opentracing.ContextWithSpan(ctx, span)
Expand Down Expand Up @@ -134,7 +137,12 @@ func trace(ctx context.Context, subsystem, name string) (opentracing.Span, conte

span.SetTag("subsystem", subsystem)

agentLog.Debugf("created span %v", span)
// This is slightly confusing: when tracing is disabled, trace spans
// are still created - but the tracer used is a NOP. Therefore, only
// display the message when tracing is really enabled.
if tracing {
agentLog.Debugf("created span %v", span)
}

return span, ctx
}

0 comments on commit 6bd0f7c

Please sign in to comment.