diff --git a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py index 5007bda50a..8df666c740 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py @@ -62,6 +62,10 @@ def home(request): .. code-block:: python + from opentelemetry.instrumentation.starlette import StarletteInstrumentor + from opentelemetry.trace import Span + from typing import Any + def server_request_hook(span: Span, scope: dict[str, Any]): if span and span.is_recording(): 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 if span and span.is_recording(): span.set_attribute("custom_user_attribute_from_response_hook", "some-value") - StarletteInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook) + StarletteInstrumentor().instrument(server_request_hook=server_request_hook, client_request_hook=client_request_hook, client_response_hook=client_response_hook) Capture HTTP request and response headers *****************************************