@@ -10,6 +10,9 @@ import (
10
10
"time"
11
11
12
12
"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"
13
16
"golang.org/x/exp/rand"
14
17
)
15
18
@@ -110,8 +113,7 @@ func (r HttpRunner) Run(ctx context.Context, script Script) (*RunResponse, error
110
113
select {
111
114
case <- ctx .Done ():
112
115
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.
115
117
return nil , fmt .Errorf ("cannot retry further: %w" , errors .Join (err , ctx .Err ()))
116
118
case <- waitTimer .C :
117
119
}
@@ -165,7 +167,21 @@ func (r HttpRunner) request(ctx context.Context, script Script) (*RunResponse, e
165
167
166
168
req .Header .Add ("content-type" , "application/json" )
167
169
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 )
169
185
if err != nil {
170
186
r .logger .Error ().Err (err ).Msg ("sending request" )
171
187
0 commit comments