From 6bd0f7c7cb34894a5ab99e3cdba2ace3eec299ae Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 15 Mar 2019 11:20:28 +0000 Subject: [PATCH] tracing: Hide trace messages unless tracing enabled 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 #482. Signed-off-by: James O. D. Hunt --- tracing.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tracing.go b/tracing.go index 9291a065ec..9efe304fe9 100644 --- a/tracing.go +++ b/tracing.go @@ -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) @@ -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 }