fix(opentelemetry): wait for trace delivery in forceFlush - #10131
fix(opentelemetry): wait for trace delivery in forceFlush#10131BridgeAR wants to merge 2 commits into
Conversation
Overall package sizeSelf size: 8.88 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 |
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: d6509e9 | Docs | View more details | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-09-10 12:37:35 Comparing candidate commit d6509e9 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2306 metrics, 7 unstable metrics.
|
87d24e7 to
60ae30d
Compare
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.
60ae30d to
d6509e9
Compare
There was a problem hiding this comment.
💡 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() |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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 👍 / 👎.
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.