Skip to content

fix(telemetry): avoid multiple flush on app closing - #20015

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
mainfrom
yannham/fix-telemetry-double-flush
Sep 4, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
mainfrom
yannham/fix-telemetry-double-flush

Conversation

@yannham

@yannham yannham commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR removes unnecessary flushing logic for telemetry happening at app closing. #19368 switched to the native Rust telemetry implementation. I suspect that the previous underlying stop() implementation didn't flush/sent app-closing event automatically, but the new native telemetry worker does on shutdown (both flush and sending app-closing), so:

  1. It's meaningless to have the send_app_closing tweak anymore on stop(): unless we change the telemetry worker in libdatadog, we can't opt out of app-closing. I kept the parameter because I feel like this ought to be fixed and not just ignored, but it was already ineffective. Happy to do the follow-up work in libdatadog to provide a way to stop the worker without sending the app-closing event if requested.
  2. It's useless to flush in the Rust wrapping code of dd-trace-py before calling to libdatadog's stop(): the worker shutdown code already takes care of the flush
  3. It's useless to explicitly flush in the Python implementation before calling to Rust (for the same reason)

The additional flush is creating the following batches for a short-lived app that does nothing:

Sent ["app-started"]
Sent ["app-dependencies-loaded", "app-heartbeat"]
Sent ["app-closing"]

While the new version does the expected

Sent ["app-started"]
Sent ["app-dependencies-loaded", "app-closing"]

This has been discovered as part of investigating #19915, and does help getting back a few dozen ms of shutdown time (50 to 100ms locally, once pooling has been enabled - see (DataDog/libdatadog#2440)) by saving one HTTPS request.

Testing

Tested locally on the repro of #19915. Included a regression test.

Risks

No major risk identified.

Additional Notes

See https://datadoghq.atlassian.net/browse/APMS-20441

@yannham
yannham requested review from a team as code owners September 2, 2026 09:13
@datadog-official

datadog-official Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: aded7a1 | Docs | View more details | Give us feedback!

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-02T09:17:11.530753Z 05f9ce5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pr-commenter

pr-commenter Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-04 10:37:27

Comparing candidate commit aded7a1 in PR branch yannham/fix-telemetry-double-flush with baseline commit f136d41 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 7 performance regressions! Performance is the same for 574 metrics, 10 unstable metrics, 1 known flaky benchmarks, 17 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+2.214µs; +2.401µs] or [+13.010%; +14.112%]

scenario:iastaspects-rstrip_aspect

  • 🟥 execution_time [+100.484µs; +107.252µs] or [+25.355%; +27.063%]

scenario:iastaspects-swapcase_noaspect

  • 🟥 execution_time [+16.057µs; +19.932µs] or [+7.794%; +9.676%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+125.202µs; +131.259µs] or [+30.488%; +31.963%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+17.347µs; +20.724µs] or [+12.426%; +14.845%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+378.761ns; +425.310ns] or [+14.048%; +15.774%]

scenario:tracer-small

  • 🟥 execution_time [+35.848µs; +37.923µs] or [+10.484%; +11.091%]

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-635.997ns; +841.373ns] or [-5.730%; +7.580%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-43.645ns; +22.659ns] or [-7.044%; +3.657%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1456.149ns; +1860.812ns] or [-8.547%; +10.922%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1339.558ns; +1102.211ns] or [-10.196%; +8.389%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-276.779ns; +375.988ns] or [-7.522%; +10.218%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-232.003ns; +274.737ns] or [-7.862%; +9.310%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-62.710ns; +85.039ns] or [-5.498%; +7.455%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3927.850ns; +4086.560ns] or [-9.577%; +9.964%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-679.200ns; +854.286ns] or [-8.439%; +10.615%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-53.875µs; +56.762µs] or [-9.319%; +9.819%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:span-start

  • 🟥 execution_time [+1.694ms; +1.854ms] or [+11.926%; +13.054%]

Known flaky benchmarks without significant changes:

  • scenario:errortrackingflasksqli-baseline
  • scenario:flasksimple-iast-get
  • scenario:iastaspects-casefold_aspect
  • scenario:iastaspects-casefold_noaspect
  • scenario:iastaspects-index_aspect
  • scenario:iastaspects-ljust_noaspect
  • scenario:iastaspects-lower_aspect
  • scenario:iastaspects-replace_aspect
  • scenario:iastaspects-swapcase_aspect
  • scenario:iastaspects-title_noaspect
  • scenario:iastaspects-translate_aspect
  • scenario:iastaspects-translate_noaspect
  • scenario:iastaspects-upper_noaspect
  • scenario:packagespackageforrootmodulemapping-cache_off
  • scenario:packagespackageforrootmodulemapping-cache_on
  • scenario:sethttpmeta-all-enabled
  • scenario:telemetryaddmetric-record-100-metrics

@yannham
yannham force-pushed the yannham/fix-telemetry-double-flush branch from 05f9ce5 to 9a8ebf9 Compare September 2, 2026 09:39
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

No remaining files require a CODEOWNERS review.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 230 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 230 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.debugging._signal.tracing -×-> ddtrace.trace  (product:debugging -> product:tracing, score=132)
ddtrace.llmobs._evaluators.runner -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.profiling.collector.stack -×-> ddtrace.trace  (product:profiling -> product:tracing, score=132)
ddtrace.profiling.scheduler -×-> ddtrace.trace  (product:profiling -> product:tracing, score=132)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 3 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@yannham yannham added changelog/no-changelog A changelog entry is not required for this PR. and removed changelog/no-changelog A changelog entry is not required for this PR. labels Sep 2, 2026

@emmettbutler emmettbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@yannham
yannham force-pushed the yannham/fix-telemetry-double-flush branch from 88dd8bb to 99c7e11 Compare September 3, 2026 08:46
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 6ad4c28 into main Sep 4, 2026
1395 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the yannham/fix-telemetry-double-flush branch September 4, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants