Skip to content

Commit 42464e7

Browse files
committed
Improve type hints of asgi instrumentation example
1 parent edba8ee commit 42464e7

File tree

1 file changed

+5
-4
lines changed
  • instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ async def hello():
8383
8484
from opentelemetry.trace import Span
8585
from typing import Any
86+
from asgiref.typing import Scope, ASGIReceiveEvent, ASGISendEvent
8687
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
8788
88-
async def application(scope: dict[str, Any], receive: Any, send: Any):
89+
async def application(scope: Scope, receive: ASGIReceiveEvent, send: ASGISendEvent):
8990
await send({
9091
'type': 'http.response.start',
9192
'status': 200,
@@ -99,15 +100,15 @@ async def application(scope: dict[str, Any], receive: Any, send: Any):
99100
'body': b'Hello, world!',
100101
})
101102
102-
def server_request_hook(span: Span, scope: dict[str, Any]):
103+
def server_request_hook(span: Span, scope: Scope):
103104
if span and span.is_recording():
104105
span.set_attribute("custom_user_attribute_from_request_hook", "some-value")
105106
106-
def client_request_hook(span: Span, scope: dict[str, Any], message: dict[str, Any]):
107+
def client_request_hook(span: Span, scope: Scope, message: dict[str, Any]):
107108
if span and span.is_recording():
108109
span.set_attribute("custom_user_attribute_from_client_request_hook", "some-value")
109110
110-
def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, Any]):
111+
def client_response_hook(span: Span, scope: Scope, message: dict[str, Any]):
111112
if span and span.is_recording():
112113
span.set_attribute("custom_user_attribute_from_response_hook", "some-value")
113114

0 commit comments

Comments
 (0)