File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ cc_library(
4545 "src/datadog/propagation_style.cpp" ,
4646 "src/datadog/random.cpp" ,
4747 "src/datadog/random.h" ,
48+ "src/datadog/root_session_id.cpp" ,
4849 "src/datadog/root_session_id.h" ,
4950 "src/datadog/rate.cpp" ,
5051 "src/datadog/remote_config/product.cpp" ,
Original file line number Diff line number Diff line change @@ -197,6 +197,7 @@ target_sources(dd-trace-cpp-objects
197197 src/datadog/parse_util.cpp
198198 src/datadog/propagation_style.cpp
199199 src/datadog/random.cpp
200+ src/datadog/root_session_id.cpp
200201 src/datadog/rate.cpp
201202 src/datadog/remote_config/product.cpp
202203 src/datadog/remote_config/remote_config.cpp
Original file line number Diff line number Diff line change 1+ #include " root_session_id.h"
2+
3+ #include < mutex>
4+
5+ namespace datadog {
6+ namespace tracing {
7+ namespace root_session_id {
8+
9+ namespace {
10+
11+ std::string& instance () {
12+ static std::string id;
13+ return id;
14+ }
15+
16+ std::once_flag& flag () {
17+ static std::once_flag f;
18+ return f;
19+ }
20+
21+ } // namespace
22+
23+ void set (const std::string& id) {
24+ std::call_once (flag (), [&]() { instance () = id; });
25+ }
26+
27+ const std::string& get () { return instance (); }
28+
29+ } // namespace root_session_id
30+ } // namespace tracing
31+ } // namespace datadog
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < mutex>
43#include < string>
54
65namespace datadog {
76namespace tracing {
7+ namespace root_session_id {
88
99// Thread-safe singleton for the root session ID. The first call to `set`
1010// captures the value; subsequent calls are no-ops. Immutable after init,
1111// so fork-safe.
12-
13- namespace root_session_id {
14-
15- inline std::string& instance () {
16- static std::string id;
17- return id;
18- }
19-
20- inline std::once_flag& flag () {
21- static std::once_flag f;
22- return f;
23- }
24-
25- inline void set (const std::string& id) {
26- std::call_once (flag (), [&]() { instance () = id; });
27- }
28-
29- inline const std::string& get () { return instance (); }
12+ void set (const std::string& id);
13+ const std::string& get ();
3014
3115} // namespace root_session_id
32-
3316} // namespace tracing
3417} // namespace datadog
You can’t perform that action at this time.
0 commit comments