From 6d669b912d76d4ea7db22aab84575c2a5fa41277 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Tue, 16 Aug 2022 10:17:44 +0100
Subject: [PATCH] Set WithPublicEndpoint() on the otelhttp client tracer

Should prevent creation of client spans unless there's an incoming
parent span already.
---
 tracing/tracing.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tracing/tracing.go b/tracing/tracing.go
index 8357690..739eda6 100644
--- a/tracing/tracing.go
+++ b/tracing/tracing.go
@@ -72,7 +72,10 @@ func getServiceName() string {
 	if s := os.Getenv("TRACING_SERVICE"); s != "" {
 		return s
 	}
-	return filepath.Base(os.Args[0])
+	if s, err := os.Executable(); err == nil {
+		return filepath.Base(s)
+	}
+	return "unknown_service"
 }
 
 func defaultResource(serviceName string) *resource.Resource {
@@ -143,7 +146,7 @@ func initTracing(serviceName string) {
 
 // Init tracing support, if not using WrapHandler.
 func Init() {
-	initTracing("")
+	initTracing(getServiceName())
 }
 
 // WrapTransport optionally wraps a http.RoundTripper with OpenCensus
@@ -152,7 +155,7 @@ func Init() {
 // Must call Init() first.
 func WrapTransport(t http.RoundTripper) http.RoundTripper {
 	if Enabled {
-		t = othttp.NewTransport(t)
+		t = othttp.NewTransport(t, othttp.WithPublicEndpoint())
 	}
 	return t
 }
-- 
GitLab