@@ -57,6 +57,97 @@ def response_hook(span, request_obj, response):
5757 request_hook=request_hook, response_hook=response_hook
5858 )
5959
60+ Capture HTTP request and response headers
61+ *****************************************
62+ You can configure the agent to capture specified HTTP headers as span attributes, according to the
63+ `semantic conventions <https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-client-span>`_.
64+
65+ Request headers
66+ ***************
67+ To capture HTTP request headers as span attributes, set the environment variable
68+ ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST`` to a comma delimited list of HTTP header names.
69+
70+ For example using the environment variable,
71+ ::
72+
73+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST="content-type,custom_request_header"
74+
75+ will extract ``content-type`` and ``custom_request_header`` from the request headers and add them as span attributes.
76+
77+ Request header names in Requests are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
78+ variable will capture the header named ``custom-header``.
79+
80+ Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
81+ ::
82+
83+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST="Accept.*,X-.*"
84+
85+ Would match all request headers that start with ``Accept`` and ``X-``.
86+
87+ To capture all request headers, set ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST`` to ``".*"``.
88+ ::
89+
90+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST=".*"
91+
92+ The name of the added span attribute will follow the format ``http.request.header.<header_name>`` where ``<header_name>``
93+ is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
94+ single item list containing all the header values.
95+
96+ For example:
97+ ``http.request.header.custom_request_header = ["<value1>", "<value2>"]``
98+
99+ Response headers
100+ ****************
101+ To capture HTTP response headers as span attributes, set the environment variable
102+ ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE`` to a comma delimited list of HTTP header names.
103+
104+ For example using the environment variable,
105+ ::
106+
107+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE="content-type,custom_response_header"
108+
109+ will extract ``content-type`` and ``custom_response_header`` from the response headers and add them as span attributes.
110+
111+ Response header names in Requests are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
112+ variable will capture the header named ``custom-header``.
113+
114+ Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
115+ ::
116+
117+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE="Content.*,X-.*"
118+
119+ Would match all response headers that start with ``Content`` and ``X-``.
120+
121+ To capture all response headers, set ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE`` to ``".*"``.
122+ ::
123+
124+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE=".*"
125+
126+ The name of the added span attribute will follow the format ``http.response.header.<header_name>`` where ``<header_name>``
127+ is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
128+ list containing the header values.
129+
130+ For example:
131+ ``http.response.header.custom_response_header = ["<value1>", "<value2>"]``
132+
133+ Sanitizing headers
134+ ******************
135+ In order to prevent storing sensitive data such as personally identifiable information (PII), session keys, passwords,
136+ etc, set the environment variable ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS``
137+ to a comma delimited list of HTTP header names to be sanitized.
138+
139+ Regexes may be used, and all header names will be matched in a case-insensitive manner.
140+
141+ For example using the environment variable,
142+ ::
143+
144+ export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS=".*session.*,set-cookie"
145+
146+ will replace the value of headers such as ``session-id`` and ``set-cookie`` with ``[REDACTED]`` in the span.
147+
148+ Note:
149+ The environment variable names used to capture HTTP headers are still experimental, and thus are subject to change.
150+
60151Custom Duration Histogram Boundaries
61152************************************
62153To customize the duration histogram bucket boundaries used for HTTP client request duration metrics,
0 commit comments