@@ -186,7 +186,7 @@ def response_hook(span, request_obj, response):
186186import functools
187187import types
188188from timeit import default_timer
189- from typing import Any , Callable , Collection , Mapping , Optional
189+ from typing import Any , Callable , Collection , Optional
190190from urllib .parse import urlparse
191191
192192from requests .models import PreparedRequest , Response
@@ -245,8 +245,8 @@ def response_hook(span, request_obj, response):
245245 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE ,
246246 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ,
247247 ExcludeList ,
248- SanitizeValue ,
249248 detect_synthetic_user_agent ,
249+ get_custom_header_attributes ,
250250 get_custom_headers ,
251251 get_excluded_urls ,
252252 normalise_request_header_name ,
@@ -289,35 +289,6 @@ def _set_http_status_code_attribute(
289289 )
290290
291291
292- def _get_custom_header_attributes (
293- headers : Mapping [str , str | list [str ]] | None ,
294- captured_headers : list [str ] | None ,
295- sensitive_headers : list [str ] | None ,
296- normalize_function : Callable [[str ], str ],
297- ) -> dict [str , list [str ]]:
298- """Extract and sanitize HTTP headers for span attributes.
299-
300- Args:
301- headers: The HTTP headers to process, either from a request or response.
302- Can be None if no headers are available.
303- captured_headers: List of header regexes to capture as span attributes.
304- If None or empty, no headers will be captured.
305- sensitive_headers: List of header regexes whose values should be sanitized
306- (redacted). If None, no sanitization is applied.
307- normalize_function: Function to normalize header names.
308-
309- Returns:
310- Dictionary of normalized header attribute names to their values
311- as lists of strings.
312- """
313- if not headers or not captured_headers :
314- return {}
315- sanitize : SanitizeValue = SanitizeValue (sensitive_headers or ())
316- return sanitize .sanitize_header_values (
317- headers , captured_headers , normalize_function
318- )
319-
320-
321292# pylint: disable=unused-argument
322293# pylint: disable=R0915
323294def _instrument (
@@ -389,7 +360,7 @@ def get_or_create_headers():
389360 if user_agent :
390361 span_attributes [USER_AGENT_ORIGINAL ] = user_agent
391362 span_attributes .update (
392- _get_custom_header_attributes (
363+ get_custom_header_attributes (
393364 headers ,
394365 captured_request_headers ,
395366 sensitive_headers ,
@@ -489,7 +460,7 @@ def get_or_create_headers():
489460 sem_conv_opt_in_mode ,
490461 )
491462 span_attributes .update (
492- _get_custom_header_attributes (
463+ get_custom_header_attributes (
493464 result .headers ,
494465 captured_response_headers ,
495466 sensitive_headers ,
0 commit comments