Skip to content

Commit 974b015

Browse files
committed
Reset distributed context on request init (#2340)
1 parent 93664fd commit 974b015

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

ext/ddtrace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ static void dd_rinit_once(void) {
931931
static pthread_once_t dd_rinit_once_control = PTHREAD_ONCE_INIT;
932932

933933
static void dd_initialize_request(void) {
934+
DDTRACE_G(distributed_trace_id) = (ddtrace_trace_id){0};
935+
DDTRACE_G(distributed_parent_trace_id) = 0;
934936
DDTRACE_G(additional_global_tags) = zend_new_array(0);
935937
DDTRACE_G(default_priority_sampling) = DDTRACE_PRIORITY_SAMPLING_UNKNOWN;
936938
DDTRACE_G(propagated_priority_sampling) = DDTRACE_PRIORITY_SAMPLING_UNSET;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--TEST--
2+
Reset distributed tracing context on request init
3+
--ENV--
4+
DD_TRACE_GENERATE_ROOT_SPAN=0
5+
--FILE--
6+
<?php
7+
// Initial state
8+
var_dump(DDTrace\current_context());
9+
10+
// Update distributed tracing context
11+
DDTrace\set_distributed_tracing_context("123", "321");
12+
var_dump(DDTrace\current_context());
13+
14+
// Reinitialize request to clear the distributed context state
15+
ini_set("datadog.trace.enabled", 0);
16+
ini_set("datadog.trace.enabled", 1);
17+
18+
// Reinitialized state
19+
var_dump(DDTrace\current_context());
20+
21+
?>
22+
--EXPECT--
23+
array(5) {
24+
["trace_id"]=>
25+
string(1) "0"
26+
["span_id"]=>
27+
string(1) "0"
28+
["version"]=>
29+
NULL
30+
["env"]=>
31+
NULL
32+
["distributed_tracing_propagated_tags"]=>
33+
array(0) {
34+
}
35+
}
36+
array(6) {
37+
["trace_id"]=>
38+
string(3) "123"
39+
["span_id"]=>
40+
string(3) "321"
41+
["version"]=>
42+
NULL
43+
["env"]=>
44+
NULL
45+
["distributed_tracing_parent_id"]=>
46+
string(3) "321"
47+
["distributed_tracing_propagated_tags"]=>
48+
array(0) {
49+
}
50+
}
51+
array(5) {
52+
["trace_id"]=>
53+
string(1) "0"
54+
["span_id"]=>
55+
string(1) "0"
56+
["version"]=>
57+
NULL
58+
["env"]=>
59+
NULL
60+
["distributed_tracing_propagated_tags"]=>
61+
array(0) {
62+
}
63+
}

0 commit comments

Comments
 (0)