diff --git a/tracing/tracing.go b/tracing/tracing.go index d1b88b9df252b46cd02d35e88be022656d54ca46..d4185014b2b58f9308d72e56a247779f1c975641 100644 --- a/tracing/tracing.go +++ b/tracing/tracing.go @@ -148,6 +148,8 @@ func Init() { // WrapTransport optionally wraps a http.RoundTripper with OpenCensus // tracing functionality, if it is globally enabled. +// +// Must call Init() first. func WrapTransport(t http.RoundTripper) http.RoundTripper { if Enabled { t = othttp.NewTransport(t) @@ -158,10 +160,10 @@ func WrapTransport(t http.RoundTripper) http.RoundTripper { // WrapHandler wraps a http.Handler with OpenCensus tracing // functionality, if globally enabled. Automatically calls Init(). func WrapHandler(h http.Handler, endpointAddr string) http.Handler { - if Enabled { - serviceName := getServiceName() - initTracing(serviceName) - h = othttp.NewHandler(h, serviceName) + serviceName := getServiceName() + initTracing(serviceName) + if !Enabled { + return h } - return h + return othttp.NewHandler(h, serviceName) }