Repository navigation
chore(telemetry): add fork-child identity, lifecycle and replay controls to the native worker - #21615
Draft
VianneyRuhlmann wants to merge 1 commit into
Draft
VianneyRuhlmann wants to merge 1 commit into
VianneyRuhlmann wants to merge 1 commit into
Conversation
…ols to the native worker Expose set_identity, set_app_lifecycle and stage_fork_replay on the native TelemetryWorker so a forked child can switch to its own runtime/session identity, suppress app-started/app-closing, and replay its configuration, integrations and products right after the worker's fork reset, before the worker restarts. None of these restart the runtime, so they can be applied while the child restart is pending or deferred. set_app_lifecycle requires the libdatadog TelemetryWorkerHandle lifecycle switches (DataDog/libdatadog#2837).
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
Contributor
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 205 Pipeline jobs failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 05203fd | Docs | View more details | Give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The native
TelemetryWorkersets its runtime/session identity and lifecycle behavior only at construction. A forked process that wants to keep the existing worker therefore cannot switch it to the child's identity or prevent it from sending lifecycle events. This PR adds controls a forked child can apply before the worker restarts. None of them restart the runtime, so they also work while the child restart is pending or deferred:set_identity(runtime_id, session_id, parent_session_id=None, root_session_id=None): identity now goes through libdatadog's mutable metadata. Every later request uses the new runtime id and thedd-session-id,dd-parent-session-idanddd-root-session-idheaders.set_app_lifecycle(*, app_started, app_closing): turnsapp-started/app-closingon or off for an already-built worker.emit_app_lifecycleremains the initial value. Per the telemetry API, forked children must not sendapp-started. They also skipapp-closing, which closes the lifecycleapp-startedopened. They still heartbeat under their own identity.stage_fork_replay(configurations, integrations=(), products=()): the fork reset clears inherited configurations, integrations, products and dependencies, along with their dedupe history. A small worker wrapper queues staged items right after that reset, before the worker restarts. The replay therefore cannot race Python threads on configurationseq_ids. Staged items are consumed once.This PR only adds and tests the controls. The fork hooks still rebuild the worker as before. Switching them to keep the worker comes in a follow-up.
Testing
tests/telemetry/test_native_worker_fork_controls.py(new): subprocess tests against the test agent. Each test drives a standalone worker and simulates the child sequence with the runtime fork hooks (before_fork→ controls →after_fork_child).seq_id1, and sends noapp-startedorapp-closing.app-client-configuration-change.start()sends noapp-started.defer_after_fork_child()is active.src/native/telemetry.rscover the wrapper. Staged items are queued after a child reset and consumed once. Nothing is injected when nothing is staged or the handle is gone. Parent resume leaves staged items untouched.scripts/run-tests -ron Python 3.12, and 4 Rust tests pass viacargo nextest.tests/telemetry/test_telemetry.pyandtest_writer.py(135) still pass.cargo clippy --all-features -- -D warnings,cargo +nightly fmtandscripts/lint checksare clean.Risks
set_app_lifecycledepends on new libdatadog API (feat(telemetry): allow toggling app-started/app-closing on a built worker libdatadog#2837). Until a libdatadog release containing it is pinned here, this branch does not build against the currentv48.0.0pin, and CI is expected to fail. The PR stays in draft until the libdatadog version bump lands, and it must not merge on a non-tag pin.Additional Notes
changelog/no-changelog): this adds internal native APIs with no user-visible behavior change yet.stop(send_app_closing)still ignores its argument. Stopping withoutapp-closingis now done throughset_app_lifecycle.