Skip to content

Commit

Permalink
Reset distributed context on request init (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Oct 31, 2023
1 parent 172605f commit f99eb9c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ static void dd_rinit_once(void) {
static pthread_once_t dd_rinit_once_control = PTHREAD_ONCE_INIT;

static void dd_initialize_request(void) {
DDTRACE_G(distributed_trace_id) = (ddtrace_trace_id){0};
DDTRACE_G(distributed_parent_trace_id) = 0;
DDTRACE_G(additional_global_tags) = zend_new_array(0);
DDTRACE_G(default_priority_sampling) = DDTRACE_PRIORITY_SAMPLING_UNKNOWN;
DDTRACE_G(propagated_priority_sampling) = DDTRACE_PRIORITY_SAMPLING_UNSET;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--TEST--
Reset distributed tracing context on request init
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
--FILE--
<?php
// Initial state
var_dump(DDTrace\current_context());

// Update distributed tracing context
DDTrace\set_distributed_tracing_context("123", "321");
var_dump(DDTrace\current_context());

// Reinitialize request to clear the distributed context state
ini_set("datadog.trace.enabled", 0);
ini_set("datadog.trace.enabled", 1);

// Reinitialized state
var_dump(DDTrace\current_context());

?>
--EXPECT--
array(5) {
["trace_id"]=>
string(1) "0"
["span_id"]=>
string(1) "0"
["version"]=>
NULL
["env"]=>
NULL
["distributed_tracing_propagated_tags"]=>
array(0) {
}
}
array(6) {
["trace_id"]=>
string(3) "123"
["span_id"]=>
string(3) "321"
["version"]=>
NULL
["env"]=>
NULL
["distributed_tracing_parent_id"]=>
string(3) "321"
["distributed_tracing_propagated_tags"]=>
array(0) {
}
}
array(5) {
["trace_id"]=>
string(1) "0"
["span_id"]=>
string(1) "0"
["version"]=>
NULL
["env"]=>
NULL
["distributed_tracing_propagated_tags"]=>
array(0) {
}
}

0 comments on commit f99eb9c

Please sign in to comment.