Skip to content
Snippets Groups Projects
Commit 6b04d2d6 authored by ale's avatar ale
Browse files

Use service name for the Tracer

parent 25fdf0ef
No related branches found
No related tags found
No related merge requests found
...@@ -83,7 +83,7 @@ func getServiceName() string { ...@@ -83,7 +83,7 @@ func getServiceName() string {
// We need to check the configuration as soon as possible, because // We need to check the configuration as soon as possible, because
// it's likely that client transports are created before HTTP servers, // it's likely that client transports are created before HTTP servers,
// and we need to wrap them with opencensus at creation time. // and we need to wrap them with opencensus at creation time.
func initTracing(endpointAddr string) { func initTracing(serviceName string) {
initOnce.Do(func() { initOnce.Do(func() {
// Kill switch from environment. // Kill switch from environment.
if s := os.Getenv("TRACING_ENABLE"); s == "0" { if s := os.Getenv("TRACING_ENABLE"); s == "0" {
...@@ -122,7 +122,7 @@ func initTracing(endpointAddr string) { ...@@ -122,7 +122,7 @@ func initTracing(endpointAddr string) {
) )
otel.SetTracerProvider(tp) otel.SetTracerProvider(tp)
Tracer = tp.Tracer(endpointAddr) Tracer = tp.Tracer(serviceName)
log.Printf("tracing enabled (report_url %s)", config.ReportURL) log.Printf("tracing enabled (report_url %s)", config.ReportURL)
...@@ -148,8 +148,9 @@ func WrapTransport(t http.RoundTripper) http.RoundTripper { ...@@ -148,8 +148,9 @@ func WrapTransport(t http.RoundTripper) http.RoundTripper {
// functionality, if globally enabled. Automatically calls Init(). // functionality, if globally enabled. Automatically calls Init().
func WrapHandler(h http.Handler, endpointAddr string) http.Handler { func WrapHandler(h http.Handler, endpointAddr string) http.Handler {
if Enabled { if Enabled {
initTracing(endpointAddr) serviceName := getServiceName()
h = othttp.NewHandler(h, getServiceName()) initTracing(serviceName)
h = othttp.NewHandler(h, serviceName)
} }
return h return h
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment