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
Copy file name to clipboardExpand all lines: instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py
+70-25Lines changed: 70 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,9 @@ def home(request):
36
36
37
37
Exclude lists
38
38
*************
39
-
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_STARLETTE_EXCLUDED_URLS``
40
-
(or ``OTEL_PYTHON_EXCLUDED_URLS`` as fallback) with comma delimited regexes representing which URLs to exclude.
39
+
To exclude certain URLs from tracking, set the environment variable ``OTEL_PYTHON_STARLETTE_EXCLUDED_URLS``
40
+
(or ``OTEL_PYTHON_EXCLUDED_URLS`` to cover all instrumentations) to a string of comma delimited regexes that match the
41
+
URLs.
41
42
42
43
For example,
43
44
@@ -50,9 +51,14 @@ def home(request):
50
51
Request/Response hooks
51
52
**********************
52
53
53
-
Utilize request/response hooks to execute custom logic to be performed before/after performing a request. The server request hook takes in a server span and ASGI
54
-
scope object for every incoming request. The client request hook is called with the internal span and an ASGI scope which is sent as a dictionary for when the method receive is called.
55
-
The client response hook is called with the internal span and an ASGI event which is sent as a dictionary for when the method send is called.
54
+
This instrumentation supports request and response hooks. These are functions that get called
55
+
right after a span is created for a request and right before the span is finished for the response.
56
+
57
+
- The server request hook is passed a server span and ASGI scope object for every incoming request.
58
+
- The client request hook is called with the internal span and an ASGI scope when the method ``receive`` is called.
59
+
- The client response hook is called with the internal span and an ASGI event 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>`_.
79
+
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``
78
-
to a comma-separated list of HTTP header names.
84
+
To capture HTTP request headers as span attributes, set the environment variable
85
+
``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.
92
+
will extract ``content-type`` and ``custom_request_header`` from the request headers and add them as span attributes.
93
+
94
+
Request header names in Starlette are case-insensitive. So, giving the header name as ``CUStom-Header`` in the
95
+
environment variable will capture the header named ``custom-header``.
96
+
97
+
Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
98
+
::
87
99
88
-
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
89
-
Request header names in starlette are case insensitive. 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 _ ).
92
-
The value of the attribute will be single item list containing all the header values.
102
+
Would match all request headers that start with ``Accept`` and ``X-``.
93
103
94
-
Example of the added span attribute,
104
+
Additionally, the special keyword ``all`` can be used to capture all request headers.
To capture predefined HTTP response headers as span attributes, set the environment variable ``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE``
100
-
to a comma-separated list of HTTP header names.
118
+
To capture HTTP response headers as span attributes, set the environment variable
119
+
``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.
126
+
will extract ``content-type`` and ``custom_response_header`` from the response headers and add them as span attributes.
109
127
110
-
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
111
-
Response header names captured in starlette are case insensitive. So, giving header name as ``CUStomHeader`` in environment variable will be able capture header with name ``customheader``.
128
+
Response header names in Starlette are case-insensitive. So, giving the header name as ``CUStom-Header`` in the
129
+
environment variable will capture the header named ``custom-header``.
112
130
113
-
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 _ ).
114
-
The value of the attribute will be single item list containing all the header values.
131
+
Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
0 commit comments