Skip to content

test(debugger): fix race condition in test helpers#7394

Merged
BridgeAR merged 1 commit intomasterfrom
watson/fix-flaky-debugger-integration-tests
Jan 30, 2026
Merged

test(debugger): fix race condition in test helpers#7394
BridgeAR merged 1 commit intomasterfrom
watson/fix-flaky-debugger-integration-tests

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Jan 30, 2026

What does this PR do?

Attempt to fix a race condition in the debugger integration test helper function setupAssertionListeners that was likely causing flaky test failures in CI, particularly the test DD_TRACING_ENABLED=true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=falseshould capture and send expected payload when a log line probe is triggered.

The fix:

  • The 'message' listener now removes itself immediately after capturing the first valid span with t.agent.removeListener('message', messageListener)
  • The 'debugger-input' listener now uses .once() instead of .on() since we expect exactly one debugger payload per test

Motivation

The test was failing intermittently with trace ID mismatches like:

Expected: '78160144430626865'
Actual:   '5009160858555370125'

The root cause seems to be that event listeners were using .on() and persisting across multiple events. When multiple HTTP requests occurred (from background activity or timing variations), the 'message' listener would fire multiple times, updating the shared closure variables (traceId, spanId) with values from different requests. This caused assertions to compare trace IDs from mismatched requests.

Prevent event listeners in setupAssertionListeners from firing
multiple times and overwriting trace IDs. The 'message' listener
now removes itself after capturing the first valid span, and the
'debugger-input' listener uses .once() instead of .on().

This fixes flaky test failures where subsequent HTTP requests would
update the traceId/spanId variables, causing assertion mismatches.
@watson watson requested review from a team as code owners January 30, 2026 11:33
Copy link
Copy Markdown
Collaborator Author

watson commented Jan 30, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

Overall package size

Self size: 4.49 MB
Deduped: 5.32 MB
No deduping: 5.32 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.3 | 76.87 kB | 808.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@watson watson self-assigned this Jan 30, 2026
@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 bot commented Jan 30, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

❄️ 1 New flaky test detected

cypress@latest commonJS test management disabled can disable tests from integration-tests/cypress/cypress.spec.js (Datadog) (Fix with Cursor)
Cannot read properties of undefined (reading 'content')

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bc68e94 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Jan 30, 2026

Benchmarks

Benchmark execution time: 2026-01-30 11:44:44

Comparing candidate commit bc68e94 in PR branch watson/fix-flaky-debugger-integration-tests with baseline commit 2372830 in branch master.

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

@watson watson added the debugger Dynamic Instrumentation & Live Debugger label Jan 30, 2026
@BridgeAR BridgeAR merged commit 38b60f7 into master Jan 30, 2026
788 of 789 checks passed
@BridgeAR BridgeAR deleted the watson/fix-flaky-debugger-integration-tests branch January 30, 2026 11:59
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.72%. Comparing base (2372830) to head (bc68e94).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7394      +/-   ##
==========================================
- Coverage   86.07%   85.72%   -0.36%     
==========================================
  Files         510      518       +8     
  Lines       22102    22374     +272     
==========================================
+ Hits        19025    19180     +155     
- Misses       3077     3194     +117     
Flag Coverage Δ
aiguard-macos 99.09% <ø> (ø)
aiguard-ubuntu 99.09% <ø> (ø)
aiguard-windows 99.09% <ø> (ø)
apm-capabilities-tracing-macos 57.66% <ø> (-0.19%) ⬇️
apm-capabilities-tracing-ubuntu 57.65% <ø> (-0.19%) ⬇️
apm-capabilities-tracing-windows 57.27% <ø> (-0.18%) ⬇️
apm-integrations-child-process 99.19% <ø> (ø)
apm-integrations-couchbase-18 100.00% <ø> (ø)
apm-integrations-couchbase-eol 100.00% <ø> (ø)
appsec-express 62.54% <ø> (ø)
appsec-fastify 58.55% <ø> (ø)
appsec-graphql 53.40% <ø> (ø)
appsec-kafka 43.98% <ø> (ø)
appsec-ldapjs 46.04% <ø> (ø)
appsec-lodash 47.29% <ø> (ø)
appsec-macos 93.76% <ø> (ø)
appsec-mongodb-core 51.82% <ø> (ø)
appsec-mongoose 50.73% <ø> (ø)
appsec-mysql 54.16% <ø> (ø)
appsec-node-serialize 43.92% <ø> (?)
appsec-passport 48.07% <ø> (ø)
appsec-postgres 54.51% <ø> (ø)
appsec-sourcing 33.80% <ø> (ø)
appsec-template 43.92% <ø> (ø)
appsec-ubuntu 93.76% <ø> (ø)
appsec-windows 93.76% <ø> (ø)
llmobs-ai 52.09% <ø> (ø)
llmobs-anthropic 42.73% <ø> (ø)
llmobs-bedrock 40.06% <ø> (ø)
llmobs-google-genai 45.89% <ø> (ø)
llmobs-langchain 50.15% <ø> (ø)
llmobs-openai 55.62% <ø> (ø)
llmobs-vertex-ai 44.48% <ø> (ø)
platform-core 87.23% <ø> (ø)
platform-instrumentations-misc 89.16% <ø> (ø)
platform-shimmer 98.80% <ø> (?)
platform-unit-guardrails ?
profiling-macos 70.74% <ø> (ø)
profiling-ubuntu 70.74% <ø> (ø)
profiling-windows 74.20% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

dd-octo-sts bot pushed a commit that referenced this pull request Jan 31, 2026
Prevent event listeners in setupAssertionListeners from firing
multiple times and overwriting trace IDs. The 'message' listener
now removes itself after capturing the first valid span, and the
'debugger-input' listener uses .once() instead of .on().

This fixes flaky test failures where subsequent HTTP requests would
update the traceId/spanId variables, causing assertion mismatches.
@dd-octo-sts dd-octo-sts bot mentioned this pull request Jan 31, 2026
BridgeAR pushed a commit that referenced this pull request Feb 5, 2026
Prevent event listeners in setupAssertionListeners from firing
multiple times and overwriting trace IDs. The 'message' listener
now removes itself after capturing the first valid span, and the
'debugger-input' listener uses .once() instead of .on().

This fixes flaky test failures where subsequent HTTP requests would
update the traceId/spanId variables, causing assertion mismatches.
BridgeAR pushed a commit that referenced this pull request Feb 22, 2026
Prevent event listeners in setupAssertionListeners from firing
multiple times and overwriting trace IDs. The 'message' listener
now removes itself after capturing the first valid span, and the
'debugger-input' listener uses .once() instead of .on().

This fixes flaky test failures where subsequent HTTP requests would
update the traceId/spanId variables, causing assertion mismatches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Dynamic Instrumentation & Live Debugger semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants