@@ -146,6 +146,7 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
146
146
SpanAttributes .HTTP_URL : "http://127.0.0.1/" ,
147
147
SpanAttributes .NET_PEER_IP : "127.0.0.1" ,
148
148
SpanAttributes .NET_PEER_PORT : 32767 ,
149
+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
149
150
},
150
151
},
151
152
]
@@ -303,15 +304,57 @@ def test_websocket(self):
303
304
span_list = self .memory_exporter .get_finished_spans ()
304
305
self .assertEqual (len (span_list ), 6 )
305
306
expected = [
306
- "/ asgi.websocket.receive" ,
307
- "/ asgi.websocket.send" ,
308
- "/ asgi.websocket.receive" ,
309
- "/ asgi.websocket.send" ,
310
- "/ asgi.websocket.receive" ,
311
- "/ asgi" ,
307
+ {
308
+ "name" : "/ asgi.websocket.receive" ,
309
+ "kind" : trace_api .SpanKind .INTERNAL ,
310
+ "attributes" : {"type" : "websocket.connect" },
311
+ },
312
+ {
313
+ "name" : "/ asgi.websocket.send" ,
314
+ "kind" : trace_api .SpanKind .INTERNAL ,
315
+ "attributes" : {"type" : "websocket.accept" },
316
+ },
317
+ {
318
+ "name" : "/ asgi.websocket.receive" ,
319
+ "kind" : trace_api .SpanKind .INTERNAL ,
320
+ "attributes" : {
321
+ "type" : "websocket.receive" ,
322
+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
323
+ },
324
+ },
325
+ {
326
+ "name" : "/ asgi.websocket.send" ,
327
+ "kind" : trace_api .SpanKind .INTERNAL ,
328
+ "attributes" : {
329
+ "type" : "websocket.send" ,
330
+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
331
+ },
332
+ },
333
+ {
334
+ "name" : "/ asgi.websocket.receive" ,
335
+ "kind" : trace_api .SpanKind .INTERNAL ,
336
+ "attributes" : {"type" : "websocket.disconnect" },
337
+ },
338
+ {
339
+ "name" : "/ asgi" ,
340
+ "kind" : trace_api .SpanKind .SERVER ,
341
+ "attributes" : {
342
+ SpanAttributes .HTTP_SCHEME : self .scope ["scheme" ],
343
+ SpanAttributes .NET_HOST_PORT : self .scope ["server" ][1 ],
344
+ SpanAttributes .HTTP_HOST : self .scope ["server" ][0 ],
345
+ SpanAttributes .HTTP_FLAVOR : self .scope ["http_version" ],
346
+ SpanAttributes .HTTP_TARGET : self .scope ["path" ],
347
+ SpanAttributes .HTTP_URL : f'{ self .scope ["scheme" ]} ://{ self .scope ["server" ][0 ]} { self .scope ["path" ]} ' ,
348
+ SpanAttributes .NET_PEER_IP : self .scope ["client" ][0 ],
349
+ SpanAttributes .NET_PEER_PORT : self .scope ["client" ][1 ],
350
+ SpanAttributes .HTTP_STATUS_CODE : 200 ,
351
+ },
352
+ },
312
353
]
313
- actual = [span .name for span in span_list ]
314
- self .assertListEqual (actual , expected )
354
+ for span , expected in zip (span_list , expected ):
355
+ self .assertEqual (span .name , expected ["name" ])
356
+ self .assertEqual (span .kind , expected ["kind" ])
357
+ self .assertDictEqual (dict (span .attributes ), expected ["attributes" ])
315
358
316
359
def test_lifespan (self ):
317
360
self .scope ["type" ] = "lifespan"
0 commit comments