Skip to content

Commit 3ac9e8f

Browse files
committed
fix: bug in the order of options
1 parent 8d2fdfd commit 3ac9e8f

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

utils/httputil/httputil.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ func IsNetworkError(err error) bool {
135135
}
136136

137137
type sendOptions struct {
138-
body io.Reader
139-
timeout time.Duration
140-
acceptedCodes map[int]bool
141-
headers map[string]string
142-
redirect func(req *http.Request, via []*http.Request) error
143-
retry retryOptions
144-
transport http.RoundTripper
145-
ctx context.Context
138+
body io.Reader
139+
timeout time.Duration
140+
acceptedCodes map[int]bool
141+
headers map[string]string
142+
redirect func(req *http.Request, via []*http.Request) error
143+
retry retryOptions
144+
transport http.RoundTripper
145+
ctx context.Context
146+
tracingContext bool
146147

147148
// This is not a valid http option. It provides a way to override
148149
// parts of the url. For example, url.Scheme can be changed from
@@ -280,17 +281,13 @@ func SendContext(ctx context.Context) SendOption {
280281
return func(o *sendOptions) { o.ctx = ctx }
281282
}
282283

283-
// SendTracingContext sets the context and wraps the HTTP transport with otelhttp
284-
// for automatic trace context propagation via HTTP headers.
284+
// SendTracingContext sets the context and enables OpenTelemetry trace context
285+
// propagation via HTTP headers. The transport will be wrapped with otelhttp
286+
// after all options are applied.
285287
func SendTracingContext(ctx context.Context) SendOption {
286288
return func(o *sendOptions) {
287289
o.ctx = ctx
288-
// Wrap the existing transport (or default) with otelhttp
289-
baseTransport := o.transport
290-
if baseTransport == nil {
291-
baseTransport = http.DefaultTransport
292-
}
293-
o.transport = otelhttp.NewTransport(baseTransport)
290+
o.tracingContext = true
294291
}
295292
}
296293

@@ -315,6 +312,16 @@ func Send(method, rawurl string, options ...SendOption) (*http.Response, error)
315312
o(opts)
316313
}
317314

315+
// Apply tracing context wrapping AFTER all other options are processed
316+
// This ensures SendTLS and other transport options are respected
317+
if opts.tracingContext {
318+
baseTransport := opts.transport
319+
if baseTransport == nil {
320+
baseTransport = http.DefaultTransport
321+
}
322+
opts.transport = otelhttp.NewTransport(baseTransport)
323+
}
324+
318325
req, err := newRequest(method, opts)
319326
if err != nil {
320327
return nil, err

0 commit comments

Comments
 (0)