Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/5320.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-instrumentation-urllib3`: keep the pool default headers when `urlopen` is called without headers
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
return wrapped(*args, **kwargs)

# avoid modifying original headers on inject
headers = headers.copy() if headers is not None else {}
headers = headers.copy() if headers is not None else instance.headers.copy()

sanitized_method = sanitize_method(method)
span_name = _get_span_name(sanitized_method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,16 @@ def test_urlopen_mixed_args(self):
self.assertEqual(b"Hello!", response.data)
span = self.assert_span()
self.assertEqual(span.attributes["http.request.header.x_test"], ("Value",))

def test_urlopen_pool_headers(self):
URLLib3Instrumentor().uninstrument()
URLLib3Instrumentor().instrument(captured_request_headers=["X-Test"])
pool = urllib3.HTTPConnectionPool("mock", headers={"X-Test": "Value"})
response = pool.urlopen("GET", "/status/200")
self.assertEqual(b"Hello!", response.data)
span = self.assert_span()
headers = dict(Mocket.last_request().headers)
self.assertEqual(headers.get("x-test"), "Value")
self.assertIn("traceparent", headers)
self.assertEqual(span.attributes["http.request.header.x_test"], ("Value",))
self.assertEqual(pool.headers, {"X-Test": "Value"})
Loading