Skip to content

Commit a5474c3

Browse files
authored
Improve fastapi instrumentation example (#3372)
1 parent e43e8c9 commit a5474c3

File tree

1 file changed

+5
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi

1 file changed

+5
-1
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ async def foobar():
6464
6565
.. code-block:: python
6666
67+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
68+
from opentelemetry.trace import Span
69+
from typing import Any
70+
6771
def server_request_hook(span: Span, scope: dict[str, Any]):
6872
if span and span.is_recording():
6973
span.set_attribute("custom_user_attribute_from_request_hook", "some-value")
@@ -76,7 +80,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
7680
if span and span.is_recording():
7781
span.set_attribute("custom_user_attribute_from_response_hook", "some-value")
7882
79-
FastAPIInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook)
83+
FastAPIInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook)
8084
8185
Capture HTTP request and response headers
8286
*****************************************

0 commit comments

Comments
 (0)