@@ -10,6 +10,9 @@ import (
1010 "time"
1111
1212 "github.com/rs/zerolog"
13+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
14+ "go.opentelemetry.io/otel/propagation"
15+ "go.opentelemetry.io/otel/trace"
1316 "golang.org/x/exp/rand"
1417)
1518
@@ -110,8 +113,7 @@ func (r HttpRunner) Run(ctx context.Context, script Script) (*RunResponse, error
110113 select {
111114 case <- ctx .Done ():
112115 waitTimer .Stop ()
113- // TODO: Log the returned error in the Processor instead.
114- r .logger .Error ().Err (err ).Msg ("retries exhausted" )
116+ r .logger .Error ().Err (err ).Msg ("retries exhausted" ) // TODO: Log the returned error in the Processor instead.
115117 return nil , fmt .Errorf ("cannot retry further: %w" , errors .Join (err , ctx .Err ()))
116118 case <- waitTimer .C :
117119 }
@@ -165,7 +167,21 @@ func (r HttpRunner) request(ctx context.Context, script Script) (*RunResponse, e
165167
166168 req .Header .Add ("content-type" , "application/json" )
167169
168- resp , err := http .DefaultClient .Do (req )
170+ // Build a tracing-enabled http client.
171+ httpClient := http.Client {
172+ Transport : otelhttp .NewTransport (
173+ http .DefaultTransport ,
174+ otelhttp .WithTracerProvider (trace .SpanFromContext (ctx ).TracerProvider ()),
175+ // Span names do not include method and path by default to avoid cardinality explosion with paths containing
176+ // IDs. As this is not the case with this endpoint, we use a custom formatter that includes both.
177+ otelhttp .WithSpanNameFormatter (func (_ string , r * http.Request ) string {
178+ return fmt .Sprintf ("%s %s" , r .Method , r .URL .Path )
179+ }),
180+ otelhttp .WithPropagators (propagation.TraceContext {}), // Send TraceIDs in outgoing requests.
181+ ),
182+ }
183+
184+ resp , err := httpClient .Do (req )
169185 if err != nil {
170186 r .logger .Error ().Err (err ).Msg ("sending request" )
171187
0 commit comments