Skip to content

Commit ccdb2bf

Browse files
committed
rename test for separate traces
wip
1 parent 669dde3 commit ccdb2bf

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

tests/contrib/fastapi/test_fastapi.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ def test_table_query_snapshot(snapshot_client):
541541
}
542542

543543

544+
544545
@pytest.mark.subprocess(env=dict(DD_TRACE_WEBSOCKET_MESSAGES_ENABLED="true"))
545546
@snapshot(ignores=["meta._dd.span_links", "metrics.websocket.message.length"])
546547
# TODO: look into why one message is only 26 chars
@@ -587,16 +588,26 @@ def test_websocket_sampling_not_inherited(test_spans, snapshot_app):
587588
finally:
588589
fastapi_unpatch()
589590

590-
591+
@pytest.mark.subprocess(env=dict(DD_TRACE_WEBSOCKET_MESSAGES_ENABLED="true", DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES="false"))
591592
@snapshot(ignores=["meta._dd.span_links", "metrics.websocket.message.length"])
592-
def test_websocket_separate_traces(test_spans, snapshot_app):
593-
client = TestClient(snapshot_app)
593+
def test_websocket_not_separate_traces(test_spans, snapshot_app):
594+
import fastapi # noqa: F401
595+
from fastapi.testclient import TestClient
594596

595-
with override_config("fastapi", dict(_trace_asgi_websocket=True)):
596-
with client.websocket_connect("/ws") as websocket:
597-
websocket.send_text("message")
598-
websocket.receive_text()
599-
websocket.send_text("close")
597+
from ddtrace.contrib.internal.fastapi.patch import patch as fastapi_patch
598+
from ddtrace.contrib.internal.fastapi.patch import unpatch as fastapi_unpatch
599+
from tests.contrib.fastapi import app
600+
601+
fastapi_patch()
602+
try:
603+
application = app.get_app()
604+
with TestClient(application) as client:
605+
with client.websocket_connect("/ws") as websocket:
606+
websocket.send_text("message")
607+
websocket.receive_text()
608+
websocket.send_text("close")
609+
finally:
610+
fastapi_unpatch()
600611

601612

602613
@pytest.mark.snapshot(ignores=["meta._dd.span_links", "metrics.websocket.message.length"])

tests/snapshots/tests.contrib.fastapi.test_fastapi.test_websocket_separate_traces.json renamed to tests/snapshots/tests.contrib.fastapi.test_fastapi.test_websocket_not_separate_traces.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
"meta": {
1212
"_dd.base_service": "tests.contrib.fastapi",
1313
"_dd.p.dm": "-0",
14-
"_dd.p.tid": "68405e9100000000",
14+
"_dd.p.tid": "68407af200000000",
1515
"component": "fastapi",
1616
"http.upgraded": "websocket",
1717
"http.url": "ws://testserver/ws",
1818
"http.useragent": "testclient",
1919
"language": "python",
20-
"runtime-id": "46911d0351fd4628b8af947ce608ec73",
20+
"runtime-id": "afb339b9b58445e6a35a9a4697b8a428",
2121
"span.kind": "server"
2222
},
2323
"metrics": {
2424
"_dd.top_level": 1,
2525
"_dd.tracer_kr": 1.0,
2626
"_sampling_priority_v1": 1,
27-
"process_id": 66546
27+
"process_id": 98361
2828
},
29-
"duration": 736000,
30-
"start": 1749048977947815000
29+
"duration": 659000,
30+
"start": 1749056242144119000
3131
},
3232
{
3333
"name": "websocket.send",
@@ -49,8 +49,8 @@
4949
"websocket.message.frames": 1,
5050
"websocket.message.length": 27
5151
},
52-
"duration": 38000,
53-
"start": 1749048977948151000
52+
"duration": 36000,
53+
"start": 1749056242144400000
5454
},
5555
{
5656
"name": "websocket.receive",
@@ -63,7 +63,7 @@
6363
"error": 0,
6464
"meta": {
6565
"_dd.base_service": "tests.contrib.fastapi",
66-
"_dd.span_links": "[{\"trace_id\": \"68405e910000000015ed91abfe7bf691\", \"span_id\": \"9905a4b96a487d91\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
66+
"_dd.span_links": "[{\"trace_id\": \"68407af200000000efd8f30100773f55\", \"span_id\": \"06d2eec54da5c6f3\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
6767
"component": "fastapi",
6868
"span.kind": "consumer",
6969
"websocket.message.type": "text"
@@ -72,8 +72,8 @@
7272
"websocket.message.frames": 1,
7373
"websocket.message.length": 7
7474
},
75-
"duration": 66000,
76-
"start": 1749048977948286000
75+
"duration": 62000,
76+
"start": 1749056242144523000
7777
},
7878
{
7979
"name": "websocket.send",
@@ -95,8 +95,8 @@
9595
"websocket.message.frames": 1,
9696
"websocket.message.length": 12
9797
},
98-
"duration": 25000,
99-
"start": 1749048977948379000
98+
"duration": 26000,
99+
"start": 1749056242144608000
100100
},
101101
{
102102
"name": "websocket.receive",
@@ -109,7 +109,7 @@
109109
"error": 0,
110110
"meta": {
111111
"_dd.base_service": "tests.contrib.fastapi",
112-
"_dd.span_links": "[{\"trace_id\": \"68405e910000000015ed91abfe7bf691\", \"span_id\": \"9905a4b96a487d91\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
112+
"_dd.span_links": "[{\"trace_id\": \"68407af200000000efd8f30100773f55\", \"span_id\": \"06d2eec54da5c6f3\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
113113
"component": "fastapi",
114114
"span.kind": "consumer",
115115
"websocket.message.type": "text"
@@ -119,7 +119,7 @@
119119
"websocket.message.length": 5
120120
},
121121
"duration": 25000,
122-
"start": 1749048977948434000
122+
"start": 1749056242144663000
123123
},
124124
{
125125
"name": "websocket.send",
@@ -142,7 +142,7 @@
142142
"websocket.message.length": 10
143143
},
144144
"duration": 23000,
145-
"start": 1749048977948479000
145+
"start": 1749056242144709000
146146
},
147147
{
148148
"name": "websocket.close",
@@ -161,6 +161,6 @@
161161
"metrics": {
162162
"websocket.close.code": 1000
163163
},
164-
"duration": 27000,
165-
"start": 1749048977948534000
164+
"duration": 26000,
165+
"start": 1749056242144761000
166166
}]]

0 commit comments

Comments
 (0)