Skip to content

fix(opentelemetry): wait for trace delivery in forceFlush - #10131

Open
BridgeAR wants to merge 2 commits into
masterfrom
BridgeAR/2026-09-03-otel-force-flush
Open

fix(opentelemetry): wait for trace delivery in forceFlush#10131
BridgeAR wants to merge 2 commits into
masterfrom
BridgeAR/2026-09-03-otel-force-flush

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Sep 3, 2026

Copy link
Copy Markdown
Member

This fixes OpenTelemetry TracerProvider.forceFlush() resolving before Datadog trace delivery completes. The provider now waits for the exporter's completion-aware flush boundary and every configured span processor, including delayed HTTP responses and overlapping flush generations.

Exporter failures remain observable through the OpenTelemetry promise contract, while legacy background flushes keep swallowing errors; OTLP and serverless delivery paths use the same boundary without retaining completed failures.

@dd-octo-sts

dd-octo-sts Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.88 MB
Deduped: 9.55 MB
No deduping: 9.55 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.4.0 | 127.33 kB | 447.04 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 3, 2026

Copy link
Copy Markdown

Tests

All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.18% (+0.00%)

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

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.69%. Comparing base (1c48f59) to head (d6509e9).

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #10131    +/-   ##
========================================
  Coverage   98.69%   98.69%            
========================================
  Files        1008     1009     +1     
  Lines      158514   158644   +130     
  Branches       74       74            
========================================
+ Hits       156448   156581   +133     
+ Misses       2066     2063     -3     
Flag Coverage Δ
ai-guard 65.19% <65.93%> (-0.03%) ⬇️
apm-capabilities 63.76% <100.00%> (+0.10%) ⬆️
apm-integrations 81.40% <51.13%> (-0.10%) ⬇️
appsec 58.91% <65.93%> (-0.01%) ⬇️
debugger 69.82% <64.83%> (-0.04%) ⬇️
instrumentation 53.90% <65.93%> (+<0.01%) ⬆️
llmobs 79.03% <56.25%> (-0.10%) ⬇️
master-coverage 98.69% <100.00%> (?)
openfeature 66.41% <64.83%> (-0.03%) ⬇️
platform 69.26% <52.43%> (-0.07%) ⬇️
profiling 66.76% <64.83%> (-0.03%) ⬇️
serverless 65.73% <65.93%> (-0.02%) ⬇️
test-optimization 82.58% <64.83%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pr-commenter

pr-commenter Bot commented Sep 3, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-10 12:37:35

Comparing candidate commit d6509e9 in PR branch BridgeAR/2026-09-03-otel-force-flush with baseline commit 1c48f59 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2306 metrics, 7 unstable metrics.

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 ----------------------------------'

Unstable benchmarks

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

scenario:appsec-appsec-enabled-24

  • unstable max_rss_usage [-26.069MB; +8.716MB] or [-9.197%; +3.075%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-17.390MB; +15.210MB] or [-7.487%; +6.548%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable max_rss_usage [-15.604MB; +11.666MB] or [-6.288%; +4.701%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-11.224MB; -1.704MB] or [-14.940%; -2.268%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-5.928MB; +9.153MB] or [-7.588%; +11.715%]

scenario:plugin-graphql-long-with-depth-on-max-26

  • unstable max_rss_usage [-19235.301KB; +19505.701KB] or [-10.175%; +10.318%]

scenario:plugin-mongodb-core-deep-aggregate-26

  • unstable execution_time [-116.688ms; +175.156ms] or [-4.289%; +6.439%]

@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-03-otel-force-flush branch from 87d24e7 to 60ae30d Compare September 10, 2026 11:34
@BridgeAR
BridgeAR marked this pull request as ready for review September 10, 2026 11:42
@BridgeAR
BridgeAR requested review from a team as code owners September 10, 2026 11:42
This fixes OpenTelemetry TracerProvider.forceFlush() resolving before Datadog trace delivery completes. The provider now waits for the exporter's completion-aware flush boundary and every configured span processor, including delayed HTTP responses and overlapping flush generations.

Exporter failures remain observable through the OpenTelemetry promise contract, while legacy background flushes keep swallowing errors; OTLP and serverless delivery paths use the same boundary without retaining completed failures.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-03-otel-force-flush branch from 60ae30d to d6509e9 Compare September 10, 2026 12:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d6509e99ed

ℹ️ 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".

flushExporter(exporter),
this.#activeProcessor.forceFlush(),
])
const pending = this.#flush ? this.#flush.then(flush, flush) : flush()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve failures across queued flush generations

When forceFlush() is called again while an earlier flush is pending, this defers creation of the second exporter boundary and runs it after either outcome of the first promise. If a delivery that was active when both calls were made fails, the tracker removes that completed failure before the second boundary starts, so the first promise rejects but the overlapping second call incorrectly resolves. Capture each export boundary when its call is made, or propagate the relevant predecessor failure, and cover the failing overlap case.

AGENTS.md reference: AGENTS.md:L79-L79

Useful? React with 👍 / 👎.

exporter._writer?.flush()
return this.#activeProcessor.forceFlush()
const flush = () => settleAllFlushes([
flushExporter(exporter),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid treating forceFlush as Test Optimization finalization

In Test Optimization mode, the selected CiVisibilityExporter.flush(done) treats any callback-bearing flush as a final flush and, when initialization is still pending with no buffered data, aborts its capability-discovery request (ci-visibility-exporter.js lines 712–729). Calling this generic exporter path means an ordinary OpenTelemetry forceFlush() before the first test span can cancel discovery and force the exporter onto its fallback protocol, disabling supported Test Optimization capabilities for the rest of the run. Preserve the prior non-final writer flush for this exporter or add an explicit non-final completion boundary.

AGENTS.md reference: AGENTS.md:L79-L79

Useful? React with 👍 / 👎.

else resolve()
}

exporter.flush(done, { reportErrors: true })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Propagate failures from the agentless trace exporter

With DD_AGENTLESS_ENABLED, the selected AgentlessExporter.flush accepts only the callback and ignores this new reportErrors option; its writer also catches missing-endpoint, missing-key, proxy, exporter-construction, and synchronous send failures before invoking the callback without an error. Consequently, TracerProvider.forceFlush() now waits for this supported exporter but still resolves successfully when its trace was discarded, unlike the Agent and OTLP paths added here. Extend the error-reporting flush contract to the agentless exporter and cover this sibling configuration.

AGENTS.md reference: AGENTS.md:L79-L79

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant