Repository navigation
Fix Tracer - Telemetry destruction order issue - #400
Conversation
BenchmarksBenchmark execution time: 2026-11-17 12:42:21 Comparing candidate commit 56b2b0e in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 8 metrics, 0 unstable metrics.
|
38291fc to
666b38f
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
Static review supports keeping telemetry accessible during late Tracer destruction while sending app-closing only once. Runtime shutdown behavior was not exercised.
🤖 Bits Code Review · Commit 666b38f
Overview
Fix a (rare) crash when a process exits with a
Tracerinstance that lives in a static wrapper.Motivation
This is a hardening following DataDog/nginx-datadog#483. The problem was detected in the Datadog Nginx module, and fixed there by avoiding constructing a Tracer in processes where it is not needed, but the problem can still appear in another context.
Two issues were detected: the first one (
StaticOtelCtxStatesingleton) was fixed by #398; this is the second issue fix.Additional Notes
Detailed Bug Description
If a program keeps a
Tracerin a static wrapper (for example an emptystatic std::optional<Tracer>, filled later) and callsexit()while theTraceris still alive, theTracer's destructor can use the telemetry singleton afterexit()has destroyed it.The telemetry singleton is a classical local
static TelemetryProxy, in theTelemetryProxy& instance()function insrc/datadog/telemetry/telemetry.cpp.Tracerconstruction call chain:Tracer()→telemetry::init()→TelemetryProxy& instance().Tracerdestruction call chain:~Tracer()=default,Tracerhas ashared_ptr<Collector>,Collectordefault beingDatadogAgent→~DatadogAgent()→DatadogAgent::flush()→ (if trace chunks are waiting)telemetry::distribution::add()→TelemetryProxy& instance().Moreover, agent reply callbacks happening during
exit()hit the same problem.Test
We extend the test created in #398. This test uses a dedicated binary with a
Tracerinstance that lives in a static wrapper.The test failed as expected without the fix: CI with only the test commit.
References
Jira ticket: IDMPL-1240: [C++ Tracer] Tracer - Telemetry destruction order issue.
Contributor Checklist