-
Notifications
You must be signed in to change notification settings - Fork 16
Implement stable session identifier headers for telemetry #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e40dd5d
3fab2f5
d805351
1f8a254
468dd13
f124ca3
c106643
25fb7ea
d323be4
3d9252b
b3c0f73
b673a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,9 @@ Tracer::Tracer(const FinalizedTracerConfig& config, | |
| : logger_(config.logger), | ||
| runtime_id_(config.runtime_id ? *config.runtime_id | ||
| : RuntimeID::generate()), | ||
| signature_{runtime_id_, config.defaults.service, | ||
| config.defaults.environment}, | ||
| signature_{runtime_id_, | ||
| config.root_session_id.value_or(runtime_id_.string()), | ||
| config.defaults.service, config.defaults.environment}, | ||
| config_manager_(std::make_shared<ConfigManager>(config)), | ||
| collector_(/* see constructor body */), | ||
| span_sampler_( | ||
|
|
@@ -64,6 +65,9 @@ Tracer::Tracer(const FinalizedTracerConfig& config, | |
| baggage_extraction_enabled_(false), | ||
| tracing_enabled_(config.tracing_enabled), | ||
| resource_renaming_mode_(config.resource_renaming_mode) { | ||
| environment::set(environment::_DD_ROOT_CPP_SESSION_ID, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI there will be an edge case here. Since the C++ tracer doesn't have a singleton tracer instance, we may be creating one tracer instance per worker thread (e.g. web server) and if we do not assign a runtime ID at tracer construction time then each worker thread will get a unique runtime ID and (race condition) a unique root session ID. Other times we may get the same root session ID since the other thread could read the environment variable set by this line of code
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, the race exists if multiple Tracers are constructed concurrently before any of them sets the env var. Would you prefer we fix this with a std::call_once approach? Something like a get_or_init_root_session_id(fallback) function that atomically reads-or-sets the env var on first call, so all Tracers in the process get the same root session ID. That would also let us remove the config plumbing since the Tracer would resolve it directly. |
||
| signature_.root_session_id); | ||
|
|
||
| telemetry::init(config.telemetry, signature_, logger_, config.http_client, | ||
| config.event_scheduler, config.agent_url); | ||
| if (config.report_hostname) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xlamorlette-datadog this feature requires that we set an environment variable, so that child processes will receive it. However, this means now our tracer is both reading (
std::getenv) and writing (setenv) environment variables. Will we need to add a lock to both operations to ensure only one thread is getting/setting an environment variable?