feat(telemetry): shutdown with a deadline - #276
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7bf16fe885
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
421d0ab to
cfcebe6
Compare
cfcebe6 to
db8024b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db8024b5c7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6c83089 to
b8e18c9
Compare
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 16088ff | Docs | Datadog PR Page | Give us feedback! |
b8e18c9 to
f1df8df
Compare
- Replace the bool/AtomicBool registration handshake with a type-safe TelemetryUser token so the global user count can no longer underflow; the decrement is consumed exactly once via TelemetryUser::trigger_stop. - Floor the telemetry shutdown wait to at least 1s and make it non-fatal: since telemetry is signalled to stop up front and drains in parallel, an already-drained worker is now observed as stopped instead of being force-cancelled and misreported as a timeout when the deadline passed. - Document that the wait is only bounded while libdatadog honors the cancel deadline (the real fix belongs upstream in the condvar wait). - Add coverage for the disabled-config path and the shutdown-timeout path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
f1df8df to
c876f77
Compare
paullegranddc
left a comment
There was a problem hiding this comment.
What happens if I create a tracer, shut it down then create a new one latter?
Will the telemetry worker restart, and still allow sending telemetry
Nope, that's one suggestion made by codex. But I ruled it out because it's an unlikely scenario. Is it worth it? |
I'm not sure, but you could imagine a situation where the tracer is not used as a global, but a scoped object. We can tolerate not receiving telemetry if a user restarts a tracer, but I think we should at least make sure that using a shutdown telemetry handle does not panic or cause memory leaks. |
Build a tracer, shut it down (stopping the process-global telemetry worker as the last user), then build and use another tracer and shut it down too. Telemetry is a non-restartable singleton, so this pins the graceful-degradation contract: the reuse must not panic, underflow the user count, or hang, and both shutdowns must return cleanly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…fety Loop build->use->shutdown many times: after the first iteration stops the process-global worker, each later cycle pushes span activity through the stopped handle and stops it again. Asserts no panic/error/hang across cycles; comment documents running under a leak sanitizer to also cover leaks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A scoped tracer provider that is dropped (not shutdown() explicitly) must still release its telemetry-user registration: the SDK triggers shutdown from Drop on the last reference. Drop the provider off a blocking thread (its shutdown blocks) and assert it completes cleanly, then build/use/drop a second scoped provider to confirm the SDK-Drop -> token-release path stays safe. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dfb3c56 to
488f237
Compare
Add three integration tests exercising distinct shutdown paths: - telemetry disabled: no user registered, stop/wait is skipped, shutdown clean - concurrent shutdown of several providers: races the shared atomic refcount - repeated shutdown on the same handle: idempotent, no refcount underflow Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tracers (both global and scope-specific) are registered as telemetry users, so telemetry keeps track of active users and only shuts down when the last active user requests a shutdown.
I have added integration test to prove that:
@paullegranddc let me know if you can think of any other interesting tests. |
What does this PR do?
Stop telemetry (It had been completely forgotten)