Skip to content

Commit 173831c

Browse files
authored
Fix HTTPX tracing
When performing parallel requests eg. HTTPX.with_origin('https://api.ventrata.com').get('/', '/', '/‘) The parallel requests have their context nested so appear like: - HTTP GET - HTTP GET - HTTP GET This change injects the headers only with that request's context so doesn't pollute the global state and the results are what we expect: - HTTP GET - HTTP GET - HTTP GET
1 parent 2b1ce12 commit 173831c

File tree

1 file changed

+1
-3
lines changed
  • instrumentation/httpx/lib/opentelemetry/instrumentation/httpx

1 file changed

+1
-3
lines changed

instrumentation/httpx/lib/opentelemetry/instrumentation/httpx/plugin.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ def call
4242

4343
@span = tracer.start_span(span_name, attributes: attributes, kind: :client)
4444
trace_ctx = OpenTelemetry::Trace.context_with_span(@span)
45-
@trace_token = OpenTelemetry::Context.attach(trace_ctx)
4645

47-
OpenTelemetry.propagation.inject(@request.headers)
46+
OpenTelemetry.propagation.inject(@request.headers, context: trace_ctx)
4847
rescue StandardError => e
4948
OpenTelemetry.handle_error(exception: e)
5049
end
@@ -60,7 +59,6 @@ def finish(response)
6059
@span.status = Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(response.status)
6160
end
6261

63-
OpenTelemetry::Context.detach(@trace_token) if @trace_token
6462
@span.finish
6563
end
6664

0 commit comments

Comments
 (0)