From 5b9d90bac07ffc5c5ee4877a26bfe1add0532d01 Mon Sep 17 00:00:00 2001 From: Andre Murbach Maidl Date: Wed, 9 Apr 2025 13:33:38 -0300 Subject: [PATCH] Improve starlette instrumentation example --- .../src/opentelemetry/instrumentation/starlette/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 *****************************************