1111#include " ../common/environment.h"
1212#include " datadog/runtime_id.h"
1313#include " datadog/telemetry/telemetry_impl.h"
14+ #include " root_session_id.h"
1415#include " mocks/http_clients.h"
1516#include " mocks/loggers.h"
1617#include " test.h"
@@ -372,7 +373,12 @@ TELEMETRY_IMPLEMENTATION_TEST("session ID headers") {
372373 auto scheduler = std::make_shared<FakeEventScheduler>();
373374 auto url = HTTPClient::URL::parse (" http://localhost:8000" );
374375
376+ // Acquire the root session ID from the singleton.
377+ auto init_rid = RuntimeID::generate ();
378+ const auto & root_id = root_session_id::get_or_init (init_rid.string ());
379+
375380 SECTION (" root process: DD-Session-ID present, DD-Root-Session-ID absent" ) {
381+ // Simulate root process: session_id == root_session_id
376382 auto session_rid = RuntimeID::generate ();
377383 const TracerSignature sig{session_rid, session_rid.string (), " testsvc" ,
378384 " test" };
@@ -390,9 +396,7 @@ TELEMETRY_IMPLEMENTATION_TEST("session ID headers") {
390396
391397 SECTION (" child process: DD-Root-Session-ID present when different" ) {
392398 auto session_rid = RuntimeID::generate ();
393- auto root_rid = RuntimeID::generate ();
394- const TracerSignature sig{session_rid, root_rid.string (), " testsvc" ,
395- " test" };
399+ const TracerSignature sig{session_rid, root_id, " testsvc" , " test" };
396400
397401 Telemetry telemetry{*finalize_config (), sig, logger, client,
398402 scheduler, *url};
@@ -403,14 +407,12 @@ TELEMETRY_IMPLEMENTATION_TEST("session ID headers") {
403407
404408 auto root_it = client->request_headers .items .find (" DD-Root-Session-ID" );
405409 REQUIRE (root_it != client->request_headers .items .end ());
406- CHECK (root_it->second == root_rid. string () );
410+ CHECK (root_it->second == root_id );
407411 }
408412
409413 SECTION (" heartbeat includes session headers" ) {
410414 auto session_rid = RuntimeID::generate ();
411- auto root_rid = RuntimeID::generate ();
412- const TracerSignature sig{session_rid, root_rid.string (), " testsvc" ,
413- " test" };
415+ const TracerSignature sig{session_rid, root_id, " testsvc" , " test" };
414416
415417 Telemetry telemetry{*finalize_config (), sig, logger, client,
416418 scheduler, *url};
@@ -424,7 +426,7 @@ TELEMETRY_IMPLEMENTATION_TEST("session ID headers") {
424426
425427 auto root_it = client->request_headers .items .find (" DD-Root-Session-ID" );
426428 REQUIRE (root_it != client->request_headers .items .end ());
427- CHECK (root_it->second == root_rid. string () );
429+ CHECK (root_it->second == root_id );
428430 }
429431}
430432
0 commit comments