You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Utilize request/response hooks to execute custom logic to be performed before/after performing a request. Environ is an instance of WSGIEnvironment (flask.request.environ).
45
-
Response_headers is a list of key-value (tuples) representing the response headers returned from the response.
Copy file name to clipboardexpand all lines: instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py
+73-26
Original file line number
Diff line number
Diff line change
@@ -95,8 +95,9 @@ def hello():
95
95
96
96
Exclude lists
97
97
*************
98
-
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_FLASK_EXCLUDED_URLS``
99
-
(or ``OTEL_PYTHON_EXCLUDED_URLS`` as fallback) with comma delimited regexes representing which URLs to exclude.
98
+
To exclude certain URLs from tracking, set the environment variable ``OTEL_PYTHON_FLASK_EXCLUDED_URLS``
99
+
(or ``OTEL_PYTHON_EXCLUDED_URLS`` to cover all instrumentations) to a string of comma delimited regexes that match the
100
+
URLs.
100
101
101
102
For example,
102
103
@@ -106,7 +107,7 @@ def hello():
106
107
107
108
will exclude requests such as ``https://site/client/123/info`` and ``https://site/xyz/healthcheck``.
108
109
109
-
You can also pass the comma delimited regexes to the ``instrument_app`` method directly:
110
+
You can also pass comma delimited regexes directly to the ``instrument_app`` method:
110
111
111
112
.. code-block:: python
112
113
@@ -115,8 +116,15 @@ def hello():
115
116
Request/Response hooks
116
117
**********************
117
118
118
-
Utilize request/response hooks to execute custom logic to be performed before/after performing a request. Environ is an instance of WSGIEnvironment (flask.request.environ).
119
-
Response_headers is a list of key-value (tuples) representing the response headers returned from the response.
119
+
This instrumentation supports request and response hooks. These are functions that get called
120
+
right after a span is created for a request and right before the span is finished for the response.
121
+
122
+
- The client request hook is called with the internal span and an instance of WSGIEnvironment (flask.request.environ)
123
+
when the method ``receive`` is called.
124
+
- The client response hook is called with the internal span, the status of the response and a list of key-value (tuples)
125
+
representing the response headers returned from the response when the method ``send`` is called.
You can configure the agent to capture predefined HTTP headers as span attributes, according to the `semantic convention <https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers>`_.
145
+
You can configure the agent to capture specified HTTP headers as span attributes, according to the
To capture predefined HTTP request headers as span attributes, set the environment variable ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST``
142
-
to a comma-separated list of HTTP header names.
150
+
To capture HTTP request headers as span attributes, set the environment variable
151
+
``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST`` to a comma delimited list of HTTP header names.
will extract ``content-type`` and ``custom_request_header`` from request headers and add them as span attributes.
158
+
will extract ``content-type`` and ``custom_request_header`` from the request headers and add them as span attributes.
159
+
160
+
Request header names in Flask are case-insensitive and ``-`` characters are replaced by ``_``. So, giving the header
161
+
name as ``CUStom_Header`` in the environment variable will capture the header named ``custom-header``.
162
+
163
+
Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
164
+
::
151
165
152
-
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
153
-
Request header names in flask are case insensitive and - characters are replaced by _. So, giving header name as ``CUStom_Header`` in environment variable will be able capture header with name ``custom-header``.
The name of the added span attribute will follow the format ``http.request.header.<header_name>`` where ``<header_name>`` being the normalized HTTP header name (lowercase, with - characters replaced by _ ).
156
-
The value of the attribute will be single item list containing all the header values.
168
+
Would match all request headers that start with ``Accept`` and ``X-``.
157
169
158
-
Example of the added span attribute,
170
+
To capture all request headers, set ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST`` to ``".*"``.
To capture predefined HTTP response headers as span attributes, set the environment variable ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE``
164
-
to a comma-separated list of HTTP header names.
184
+
To capture HTTP response headers as span attributes, set the environment variable
185
+
``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE`` to a comma delimited list of HTTP header names.
will extract ``content-type`` and ``custom_response_header`` from response headers and add them as span attributes.
192
+
will extract ``content-type`` and ``custom_response_header`` from the response headers and add them as span attributes.
173
193
174
-
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
175
-
Response header names captured in flask are case insensitive. So, giving header name as ``CUStomHeader`` in environment variable will be able capture header with name ``customheader``.
194
+
Response header names in Flask are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
195
+
variable will capture the header named ``custom-header``.
176
196
177
-
The name of the added span attribute will follow the format ``http.response.header.<header_name>`` where ``<header_name>`` being the normalized HTTP header name (lowercase, with - characters replaced by _ ).
178
-
The value of the attribute will be single item list containing all the header values.
197
+
Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
0 commit comments