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-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py
+69-26
Original file line number
Diff line number
Diff line change
@@ -34,8 +34,9 @@ async def foobar():
34
34
35
35
Exclude lists
36
36
*************
37
-
To exclude certain URLs from being tracked, set the environment variable ``OTEL_PYTHON_FASTAPI_EXCLUDED_URLS``
38
-
(or ``OTEL_PYTHON_EXCLUDED_URLS`` as fallback) with comma delimited regexes representing which URLs to exclude.
37
+
To exclude certain URLs from tracking, set the environment variable ``OTEL_PYTHON_FASTAPI_EXCLUDED_URLS``
38
+
(or ``OTEL_PYTHON_EXCLUDED_URLS`` to cover all instrumentations) to a string of comma delimited regexes that match the
39
+
URLs.
39
40
40
41
For example,
41
42
@@ -45,7 +46,7 @@ async def foobar():
45
46
46
47
will exclude requests such as ``https://site/client/123/info`` and ``https://site/xyz/healthcheck``.
47
48
48
-
You can also pass the comma delimited regexes to the ``instrument_app`` method directly:
49
+
You can also pass comma delimited regexes directly to the ``instrument_app`` method:
49
50
50
51
.. code-block:: python
51
52
@@ -54,9 +55,12 @@ async def foobar():
54
55
Request/Response hooks
55
56
**********************
56
57
57
-
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
58
-
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.
59
-
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.
58
+
This instrumentation supports request and response hooks. These are functions that get called
59
+
right after a span is created for a request and right before the span is finished for the response.
60
+
61
+
- The server request hook is passed a server span and ASGI scope object for every incoming request.
62
+
- The client request hook is called with the internal span and an ASGI scope when the method ``receive`` is called.
63
+
- 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>`_.
83
+
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``
84
-
to a comma-separated list of HTTP header names.
88
+
To capture HTTP request headers as span attributes, set the environment variable
89
+
``OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST`` to a comma delimited list of HTTP header names.
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
95
-
Request header names in fastapi are case insensitive. So, giving header name as ``CUStom-Header`` in environment variable will be able capture header with name ``custom-header``.
106
+
Would match all request headers that start with ``Accept`` and ``X-``.
96
107
97
-
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 _ ).
98
-
The value of the attribute will be single item list containing all the header values.
108
+
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``
106
-
to a comma-separated list of HTTP header names.
122
+
To capture HTTP response headers as span attributes, set the environment variable
123
+
``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.
130
+
will extract ``content-type`` and ``custom_response_header`` from the response headers and add them as span attributes.
131
+
132
+
Response header names in FastAPI are case-insensitive. So, giving the header name as ``CUStom-Header`` in the environment
133
+
variable will capture the header named ``custom-header``.
115
134
116
-
It is recommended that you should give the correct names of the headers to be captured in the environment variable.
117
-
Response header names captured in fastapi are case insensitive. So, giving header name as ``CUStomHeader`` in environment variable will be able capture header with name ``customheader``.
135
+
Regular expressions may also be used to match multiple headers that correspond to the given pattern. For example:
136
+
::
118
137
119
-
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 _ ).
120
-
The value of the attribute will be single item list containing all the header values.
0 commit comments