Skip to content

Conversation

@xrmx
Copy link
Contributor

@xrmx xrmx commented Dec 23, 2025

Description

This PR adds support to capture and sanitize custom client headers in the urllib3 instrumentation.

Refs #3962

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • tox

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@xrmx xrmx requested a review from a team as a code owner December 23, 2025 13:32
will extract ``content-type`` and ``custom_request_header`` from the request headers and add them as span attributes.
Request header names in aiohttp are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Request header names in aiohttp are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
Request header names in urllib3 are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment

will extract ``content-type`` and ``custom_response_header`` from the response headers and add them as span attributes.
Response header names in aiohttp are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Response header names in aiohttp are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
Response header names in urllib3 are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment

Comment on lines +536 to +543
response_headers_to_set = get_custom_header_attributes(
response.headers,
captured_response_headers,
sensitive_headers,
normalise_response_header_name,
)
for header, value in response_headers_to_set.items():
span.set_attribute(header, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any reason not to just do this

Suggested change
response_headers_to_set = get_custom_header_attributes(
response.headers,
captured_response_headers,
sensitive_headers,
normalise_response_header_name,
)
for header, value in response_headers_to_set.items():
span.set_attribute(header, value)
span.set_attributes(get_custom_header_attributes(
response.headers,
captured_response_headers,
sensitive_headers,
normalise_response_header_name,
))

@herin049
Copy link
Contributor

I did a little bit of digging into the urllib source and it looks like some headers are added within OpenerDirector:open that we are currently wrapping. If we want all header information before the request is sent, we should probably wrap the HttpConnection:_send_request method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants