test(mongodb): await traced operations - #9822
Conversation
DBM propagation traces finish from the driver callback, but these tests discarded that callback and failed after the agent's 1s deadline when the operation ran slowly. Await the operation alongside the trace so backend errors surface, and give trace delivery the same 2s allowance already used by MongoDB tests. Refs: https://github.com/DataDog/dd-trace-js/actions/runs/31803050571/job/94775323451?pr=9633
MongoDB query spans finish from driver callbacks or returned promises, but the remaining trace assertions discarded that operation completion. Await both boundaries so slow operations receive the suite's existing two-second allowance and unexpected backend errors fail their owning test. Keep command completion and BSON fixtures aligned with the driver versions whose results are now observed. This is test-only; production code is unchanged.
Overall package sizeSelf size: 8.2 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 441.72 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 green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 4717f90 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-08-14 19:19:22 Comparing candidate commit 4717f90 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2282 metrics, 10 unstable metrics.
|
MongoDB changes command-rejection messages and codes between server versions while trace behavior stays the same. Matching server-owned prose made these tests fail before they could validate tracing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9822 +/- ##
========================================
Coverage 98.53% 98.53%
========================================
Files 975 975
Lines 144148 144148
Branches 12475 13020 +545
========================================
Hits 142031 142031
Misses 2117 2117 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:
|
rochdev
left a comment
There was a problem hiding this comment.
I don't understand this PR. The results were discarded on purpose, not by accident. What is the benefit of waiting for anything else than the trace? Whether the command succeeds or not is irrelevant for the test, as long as we get the trace.
|
@rochdev this is just a hardening of the tests next to the actual flaky test improvement (the timeout). If mongo fails, I think we should still surface it to know things are working. If that is not the case, we should IMO look into it, no matter that it is somewhat unrelated to the concrete test case |
MongoDB query spans finish from the driver callback or returned promise. Thirty-one tests discarded that completion signal and waited only for the mock-agent trace, so slow operations could hit the default one-second deadline before span completion. The same pattern also hid driver rejections behind trace timeouts.
Await each operation and trace together, use the existing two-second Mongo trace allowance, and build BSON fixtures with the active driver where MongoDB 5 and newer reject BSON values from an older package.