Skip to content

Commit 04f9e8d

Browse files
authored
Improve starlette instrumentation example (#3409)
1 parent 6d5a514 commit 04f9e8d

File tree

1 file changed

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

1 file changed

+5
-1
lines changed

instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def home(request):
6262
6363
.. code-block:: python
6464
65+
from opentelemetry.instrumentation.starlette import StarletteInstrumentor
66+
from opentelemetry.trace import Span
67+
from typing import Any
68+
6569
def server_request_hook(span: Span, scope: dict[str, Any]):
6670
if span and span.is_recording():
6771
span.set_attribute("custom_user_attribute_from_request_hook", "some-value")
@@ -74,7 +78,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
7478
if span and span.is_recording():
7579
span.set_attribute("custom_user_attribute_from_response_hook", "some-value")
7680
77-
StarletteInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook)
81+
StarletteInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook)
7882
7983
Capture HTTP request and response headers
8084
*****************************************

0 commit comments

Comments
 (0)