Skip to content

Commit 9c4242d

Browse files
committed
Changed span-names to asgi.{scope["type"]}.send/receive
1 parent 4a96060 commit 9c4242d

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async def __call__(self, scope, receive, send):
159159
span_name = self.name_callback(scope)
160160

161161
with self.tracer.start_as_current_span(
162-
span_name + " (connection)",
162+
span_name + " (asgi.connection)",
163163
parent_span,
164164
kind=trace.SpanKind.SERVER,
165165
attributes=collect_request_attributes(scope),
@@ -168,25 +168,21 @@ async def __call__(self, scope, receive, send):
168168
@wraps(receive)
169169
async def wrapped_receive():
170170
with self.tracer.start_as_current_span(
171-
span_name + " (unknown-receive)"
171+
span_name + " (asgi." + scope["type"] + ".receive)"
172172
) as receive_span:
173173
payload = await receive()
174174
if payload["type"] == "websocket.receive":
175175
set_status_code(receive_span, 200)
176176
receive_span.set_attribute(
177177
"http.status_text", payload["text"]
178178
)
179-
180-
receive_span.update_name(
181-
span_name + " (" + payload["type"] + ")"
182-
)
183179
receive_span.set_attribute("type", payload["type"])
184180
return payload
185181

186182
@wraps(send)
187183
async def wrapped_send(payload):
188184
with self.tracer.start_as_current_span(
189-
span_name + " (" + payload["type"] + ")"
185+
span_name + " (asgi." + scope["type"] + ".send)"
190186
) as send_span:
191187
if payload["type"] == "http.response.start":
192188
status_code = payload["status"]
@@ -196,7 +192,6 @@ async def wrapped_send(payload):
196192
send_span.set_attribute(
197193
"http.status_text", payload["text"]
198194
)
199-
200195
send_span.set_attribute("type", payload["type"])
201196
await send(payload)
202197

ext/opentelemetry-ext-asgi/tests/test_asgi_middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,25 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
9191
self.assertEqual(len(span_list), 4)
9292
expected = [
9393
{
94-
"name": "HTTP GET (http.request)",
94+
"name": "HTTP GET (asgi.http.receive)",
9595
"kind": trace_api.SpanKind.INTERNAL,
9696
"attributes": {"type": "http.request"},
9797
},
9898
{
99-
"name": "HTTP GET (http.response.start)",
99+
"name": "HTTP GET (asgi.http.send)",
100100
"kind": trace_api.SpanKind.INTERNAL,
101101
"attributes": {
102102
"http.status_code": 200,
103103
"type": "http.response.start",
104104
},
105105
},
106106
{
107-
"name": "HTTP GET (http.response.body)",
107+
"name": "HTTP GET (asgi.http.send)",
108108
"kind": trace_api.SpanKind.INTERNAL,
109109
"attributes": {"type": "http.response.body"},
110110
},
111111
{
112-
"name": "HTTP GET (connection)",
112+
"name": "HTTP GET (asgi.connection)",
113113
"kind": trace_api.SpanKind.SERVER,
114114
"attributes": {
115115
"component": "http",

0 commit comments

Comments
 (0)