From 39e01d32d5ee927ffc3056dac4f466535ec4e460 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 14 Aug 2022 16:12:47 +0100 Subject: [PATCH] Opportunistically call Init() from WrapHandler --- tracing/tracing.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tracing/tracing.go b/tracing/tracing.go index d1b88b9..d418501 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) } -- GitLab