Skip to content

Commit ac4d82e

Browse files
committed
style
update sampling on root span wip wip: style
1 parent ccdb2bf commit ac4d82e

6 files changed

+76
-73
lines changed

ddtrace/contrib/internal/asgi/middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ async def __call__(self, scope, receive, send):
259259
span.set_tags(tags)
260260

261261
global_root_span = span_from_scope(scope)
262+
set_sampling_decision_maker(global_root_span.context, 1)
262263

263264
async def wrapped_send(message):
264265
"""

tests/contrib/fastapi/test_fastapi.py

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

543543

544-
545544
@pytest.mark.subprocess(env=dict(DD_TRACE_WEBSOCKET_MESSAGES_ENABLED="true"))
546545
@snapshot(ignores=["meta._dd.span_links", "metrics.websocket.message.length"])
547546
# TODO: look into why one message is only 26 chars
@@ -588,7 +587,10 @@ def test_websocket_sampling_not_inherited(test_spans, snapshot_app):
588587
finally:
589588
fastapi_unpatch()
590589

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

tests/snapshots/tests.contrib.fastapi.test_fastapi.test_long_running_websocket_session.json

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"_dd.dm.resource": "websocket /ws",
1414
"_dd.dm.service": "fastapi",
1515
"_dd.p.dm": "-1",
16-
"_dd.p.tid": "684061ba00000000",
17-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
16+
"_dd.p.tid": "6841a72b00000000",
17+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
1818
"component": "fastapi",
1919
"language": "python",
20-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
20+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
2121
"span.kind": "consumer",
2222
"websocket.message.type": "text"
2323
},
@@ -26,12 +26,12 @@
2626
"_dd.top_level": 1,
2727
"_dd.tracer_kr": 1.0,
2828
"_sampling_priority_v1": 1,
29-
"process_id": 72191,
29+
"process_id": 5971,
3030
"websocket.message.frames": 1,
3131
"websocket.message.length": 6
3232
},
33-
"duration": 42000,
34-
"start": 1749049786839919000
33+
"duration": 34000,
34+
"start": 1749133099747597000
3535
}],
3636
[
3737
{
@@ -48,11 +48,11 @@
4848
"_dd.dm.resource": "websocket /ws",
4949
"_dd.dm.service": "fastapi",
5050
"_dd.p.dm": "-1",
51-
"_dd.p.tid": "684061ba00000000",
52-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
51+
"_dd.p.tid": "6841a72b00000000",
52+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
5353
"component": "fastapi",
5454
"language": "python",
55-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
55+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
5656
"span.kind": "consumer",
5757
"websocket.message.type": "text"
5858
},
@@ -61,12 +61,12 @@
6161
"_dd.top_level": 1,
6262
"_dd.tracer_kr": 1.0,
6363
"_sampling_priority_v1": 1,
64-
"process_id": 72191,
64+
"process_id": 5971,
6565
"websocket.message.frames": 1,
6666
"websocket.message.length": 6
6767
},
68-
"duration": 80000,
69-
"start": 1749049786940388000
68+
"duration": 103000,
69+
"start": 1749133099852970000
7070
}],
7171
[
7272
{
@@ -83,11 +83,11 @@
8383
"_dd.dm.resource": "websocket /ws",
8484
"_dd.dm.service": "fastapi",
8585
"_dd.p.dm": "-1",
86-
"_dd.p.tid": "684061bb00000000",
87-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
86+
"_dd.p.tid": "6841a72b00000000",
87+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
8888
"component": "fastapi",
8989
"language": "python",
90-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
90+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
9191
"span.kind": "consumer",
9292
"websocket.message.type": "text"
9393
},
@@ -96,12 +96,12 @@
9696
"_dd.top_level": 1,
9797
"_dd.tracer_kr": 1.0,
9898
"_sampling_priority_v1": 1,
99-
"process_id": 72191,
99+
"process_id": 5971,
100100
"websocket.message.frames": 1,
101101
"websocket.message.length": 6
102102
},
103-
"duration": 66000,
104-
"start": 1749049787043902000
103+
"duration": 38000,
104+
"start": 1749133099958337000
105105
}],
106106
[
107107
{
@@ -118,11 +118,11 @@
118118
"_dd.dm.resource": "websocket /ws",
119119
"_dd.dm.service": "fastapi",
120120
"_dd.p.dm": "-1",
121-
"_dd.p.tid": "684061bb00000000",
122-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
121+
"_dd.p.tid": "6841a72c00000000",
122+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
123123
"component": "fastapi",
124124
"language": "python",
125-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
125+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
126126
"span.kind": "consumer",
127127
"websocket.message.type": "text"
128128
},
@@ -131,12 +131,12 @@
131131
"_dd.top_level": 1,
132132
"_dd.tracer_kr": 1.0,
133133
"_sampling_priority_v1": 1,
134-
"process_id": 72191,
134+
"process_id": 5971,
135135
"websocket.message.frames": 1,
136136
"websocket.message.length": 6
137137
},
138-
"duration": 95000,
139-
"start": 1749049787144665000
138+
"duration": 49000,
139+
"start": 1749133100063644000
140140
}],
141141
[
142142
{
@@ -153,11 +153,11 @@
153153
"_dd.dm.resource": "websocket /ws",
154154
"_dd.dm.service": "fastapi",
155155
"_dd.p.dm": "-1",
156-
"_dd.p.tid": "684061bb00000000",
157-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
156+
"_dd.p.tid": "6841a72c00000000",
157+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
158158
"component": "fastapi",
159159
"language": "python",
160-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
160+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
161161
"span.kind": "consumer",
162162
"websocket.message.type": "text"
163163
},
@@ -166,12 +166,12 @@
166166
"_dd.top_level": 1,
167167
"_dd.tracer_kr": 1.0,
168168
"_sampling_priority_v1": 1,
169-
"process_id": 72191,
169+
"process_id": 5971,
170170
"websocket.message.frames": 1,
171171
"websocket.message.length": 6
172172
},
173-
"duration": 64000,
174-
"start": 1749049787246550000
173+
"duration": 48000,
174+
"start": 1749133100166195000
175175
}],
176176
[
177177
{
@@ -188,11 +188,11 @@
188188
"_dd.dm.resource": "websocket /ws",
189189
"_dd.dm.service": "fastapi",
190190
"_dd.p.dm": "-1",
191-
"_dd.p.tid": "684061bb00000000",
192-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
191+
"_dd.p.tid": "6841a72c00000000",
192+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"executed_by\"}}]",
193193
"component": "fastapi",
194194
"language": "python",
195-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
195+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
196196
"span.kind": "consumer",
197197
"websocket.message.type": "text"
198198
},
@@ -201,12 +201,12 @@
201201
"_dd.top_level": 1,
202202
"_dd.tracer_kr": 1.0,
203203
"_sampling_priority_v1": 1,
204-
"process_id": 72191,
204+
"process_id": 5971,
205205
"websocket.message.frames": 1,
206206
"websocket.message.length": 7
207207
},
208-
"duration": 68000,
209-
"start": 1749049787348371000
208+
"duration": 60000,
209+
"start": 1749133100266528000
210210
}],
211211
[
212212
{
@@ -220,24 +220,24 @@
220220
"error": 0,
221221
"meta": {
222222
"_dd.base_service": "tests.contrib.fastapi",
223-
"_dd.p.dm": "-0",
224-
"_dd.p.tid": "684061ba00000000",
223+
"_dd.p.dm": "-1",
224+
"_dd.p.tid": "6841a72b00000000",
225225
"component": "fastapi",
226226
"http.upgraded": "websocket",
227227
"http.url": "ws://testserver/ws",
228228
"http.useragent": "testclient",
229229
"language": "python",
230-
"runtime-id": "d4c149adec3c451895084b9519912f2c",
230+
"runtime-id": "14597eef9dec454cbfed6f970e20b71b",
231231
"span.kind": "server"
232232
},
233233
"metrics": {
234234
"_dd.top_level": 1,
235235
"_dd.tracer_kr": 1.0,
236236
"_sampling_priority_v1": 1,
237-
"process_id": 72191
237+
"process_id": 5971
238238
},
239-
"duration": 509469000,
240-
"start": 1749049786839308000
239+
"duration": 519724000,
240+
"start": 1749133099747147000
241241
},
242242
{
243243
"name": "websocket.send",
@@ -250,7 +250,7 @@
250250
"error": 0,
251251
"meta": {
252252
"_dd.base_service": "tests.contrib.fastapi",
253-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
253+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
254254
"component": "fastapi",
255255
"out.host": "testclient",
256256
"span.kind": "producer",
@@ -260,8 +260,8 @@
260260
"websocket.message.frames": 1,
261261
"websocket.message.length": 27
262262
},
263-
"duration": 138000,
264-
"start": 1749049786839676000
263+
"duration": 105000,
264+
"start": 1749133099747404000
265265
},
266266
{
267267
"name": "websocket.send",
@@ -274,7 +274,7 @@
274274
"error": 0,
275275
"meta": {
276276
"_dd.base_service": "tests.contrib.fastapi",
277-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
277+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
278278
"component": "fastapi",
279279
"out.host": "testclient",
280280
"span.kind": "producer",
@@ -284,8 +284,8 @@
284284
"websocket.message.frames": 1,
285285
"websocket.message.length": 6
286286
},
287-
"duration": 42000,
288-
"start": 1749049786840217000
287+
"duration": 37000,
288+
"start": 1749133099747833000
289289
},
290290
{
291291
"name": "websocket.send",
@@ -298,7 +298,7 @@
298298
"error": 0,
299299
"meta": {
300300
"_dd.base_service": "tests.contrib.fastapi",
301-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
301+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
302302
"component": "fastapi",
303303
"out.host": "testclient",
304304
"span.kind": "producer",
@@ -308,8 +308,8 @@
308308
"websocket.message.frames": 1,
309309
"websocket.message.length": 6
310310
},
311-
"duration": 51000,
312-
"start": 1749049786940705000
311+
"duration": 44000,
312+
"start": 1749133099853209000
313313
},
314314
{
315315
"name": "websocket.send",
@@ -322,7 +322,7 @@
322322
"error": 0,
323323
"meta": {
324324
"_dd.base_service": "tests.contrib.fastapi",
325-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
325+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
326326
"component": "fastapi",
327327
"out.host": "testclient",
328328
"span.kind": "producer",
@@ -332,8 +332,8 @@
332332
"websocket.message.frames": 1,
333333
"websocket.message.length": 6
334334
},
335-
"duration": 47000,
336-
"start": 1749049787044131000
335+
"duration": 48000,
336+
"start": 1749133099958483000
337337
},
338338
{
339339
"name": "websocket.send",
@@ -346,7 +346,7 @@
346346
"error": 0,
347347
"meta": {
348348
"_dd.base_service": "tests.contrib.fastapi",
349-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
349+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
350350
"component": "fastapi",
351351
"out.host": "testclient",
352352
"span.kind": "producer",
@@ -356,8 +356,8 @@
356356
"websocket.message.frames": 1,
357357
"websocket.message.length": 6
358358
},
359-
"duration": 51000,
360-
"start": 1749049787144967000
359+
"duration": 41000,
360+
"start": 1749133100063820000
361361
},
362362
{
363363
"name": "websocket.send",
@@ -370,7 +370,7 @@
370370
"error": 0,
371371
"meta": {
372372
"_dd.base_service": "tests.contrib.fastapi",
373-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
373+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
374374
"component": "fastapi",
375375
"out.host": "testclient",
376376
"span.kind": "producer",
@@ -380,8 +380,8 @@
380380
"websocket.message.frames": 1,
381381
"websocket.message.length": 6
382382
},
383-
"duration": 45000,
384-
"start": 1749049787246782000
383+
"duration": 42000,
384+
"start": 1749133100166368000
385385
},
386386
{
387387
"name": "websocket.send",
@@ -394,7 +394,7 @@
394394
"error": 0,
395395
"meta": {
396396
"_dd.base_service": "tests.contrib.fastapi",
397-
"_dd.span_links": "[{\"trace_id\": \"684061ba00000000cebde93c1550150e\", \"span_id\": \"8df6a78712470a9d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
397+
"_dd.span_links": "[{\"trace_id\": \"6841a72b00000000af5bb74c4407795d\", \"span_id\": \"1f8529228a21093d\", \"attributes\": {\"dd.kind\": \"resuming\"}}]",
398398
"component": "fastapi",
399399
"out.host": "testclient",
400400
"span.kind": "producer",
@@ -404,8 +404,8 @@
404404
"websocket.message.frames": 1,
405405
"websocket.message.length": 3
406406
},
407-
"duration": 49000,
408-
"start": 1749049787348612000
407+
"duration": 41000,
408+
"start": 1749133100266729000
409409
},
410410
{
411411
"name": "websocket.close",
@@ -425,6 +425,6 @@
425425
"metrics": {
426426
"websocket.close.code": 1000
427427
},
428-
"duration": 32000,
429-
"start": 1749049787348709000
428+
"duration": 31000,
429+
"start": 1749133100266813000
430430
}]]

0 commit comments

Comments
 (0)