Skip to content

fix(datastreams): flush on write when flushInterval is 0#9120

Merged
BridgeAR merged 1 commit into
masterfrom
BridgeAR/2026-06-27-fix-amqplib-dsm-flake
Jul 2, 2026
Merged

fix(datastreams): flush on write when flushInterval is 0#9120
BridgeAR merged 1 commit into
masterfrom
BridgeAR/2026-06-27-fix-amqplib-dsm-flake

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

Summary

The amqplib DSM spec (Should emit DSM stats to the agent when sending a message on an unnamed exchange) flakes with a timeout because the DataStreamsProcessor is the only flushInterval consumer that doesn't honor flushInterval === 0 as a flush-on-write sentinel.

Under the test-agent config (flushInterval: 0, the same value the AWS Lambda path uses), the processor armed setInterval(onInterval, 0). That timer fires on every event-loop tick, decoupled from when a checkpoint is recorded. A tick that lands in the window where the test agent has torn its HTTP listener down and not yet brought it back up posts to a dead port (ECONNREFUSED); buckets are cleared on serialize, so that single payload is gone. A producer-only DSM test waiting on exactly one payload then times out.

The fix aligns the processor with the agent and agentless trace exporters, which already branch on flushInterval === 0: skip the timer and flush each checkpoint, offset, and transaction the moment it is recorded, while the writer URL is known live.

Test plan

  • packages/dd-trace/test/datastreams/flush_on_write.spec.js is new: it pins both branches — flushInterval: 0 arms no timer and flushes synchronously on recordCheckpoint / recordOffset / trackTransaction; a non-zero interval arms the timer and does not flush on record. It fails on master (the timer is armed, nothing flushes on write) and passes with the fix.
  • All packages/dd-trace/test/datastreams/*.spec.js pass unchanged.

Refs: https://github.com/DataDog/dd-trace-js/actions/runs/28302648699/job/83853526808

With `flushInterval: 0` (the test-agent config and the AWS Lambda config) the
processor armed `setInterval(onInterval, 0)`, which fires on every event-loop
tick instead of when a checkpoint is recorded. A tick landing in the window
between the test agent tearing its listener down and bringing it back up posts
to a dead port; the bucket is cleared on serialize, so that single payload is
lost. A producer-only DSM test waiting on exactly one payload then times out.

Honor `flushInterval === 0` as the flush-on-write sentinel the agent and
agentless trace exporters already use: skip the timer and push each checkpoint,
offset, and transaction the moment it is recorded, while the writer URL is live.

Refs: https://github.com/DataDog/dd-trace-js/actions/runs/28302648699/job/83853526808
@dd-octo-sts

dd-octo-sts Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.4 MB
Deduped: 7.46 MB
No deduping: 7.46 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 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-official

datadog-official Bot commented Jun 27, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.98% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8717cf0 | Docs | Datadog PR Page | Give us feedback!

@BridgeAR
BridgeAR marked this pull request as ready for review June 27, 2026 22:24
@BridgeAR
BridgeAR requested a review from a team as a code owner June 27, 2026 22:24
@pr-commenter

pr-commenter Bot commented Jun 27, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-27 22:25:02

Comparing candidate commit 8717cf0 in PR branch BridgeAR/2026-06-27-fix-amqplib-dsm-flake with baseline commit 27dcc31 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2259 metrics, 27 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-20

  • unstable execution_time [-188.656ms; +185.938ms] or [-5.073%; +5.000%]

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-183.201ms; +176.559ms] or [-7.014%; +6.759%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-210.318ms; +213.263ms] or [-8.370%; +8.488%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-159760.637µs; +158606.104µs] or [-5.554%; +5.514%]

scenario:appsec-control-20

  • unstable execution_time [-156.393ms; +161.398ms] or [-8.963%; +9.250%]

scenario:appsec-control-24

  • unstable execution_time [-103.972ms; +85.204ms] or [-8.654%; +7.092%]

scenario:appsec-control-26

  • unstable execution_time [-114.753ms; +111.757ms] or [-9.475%; +9.228%]

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

  • unstable cpu_user_time [-1799.042ms; +756.035ms] or [-19.463%; +8.179%]
  • unstable execution_time [-1844.488ms; +792.190ms] or [-18.584%; +7.982%]
  • unstable instructions [-16.1G instructions; +6.3G instructions] or [-21.046%; +8.242%]
  • unstable throughput [-207.349op/s; +391.232op/s] or [-6.233%; +11.761%]

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

  • unstable cpu_user_time [-1866.646ms; +2957.515ms] or [-23.574%; +37.351%]
  • unstable execution_time [-1879.261ms; +2969.369ms] or [-21.906%; +34.613%]
  • unstable instructions [-15.9G instructions; +25.2G instructions] or [-24.667%; +39.124%]
  • unstable max_rss_usage [-6.697MB; +10.926MB] or [-4.247%; +6.929%]
  • unstable throughput [-882.678op/s; +561.144op/s] or [-22.962%; +14.598%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-1.996s; +6.261s] or [-18.288%; +57.360%]
  • unstable execution_time [-2.072s; +6.374s] or [-17.817%; +54.809%]
  • unstable instructions [-17.1G instructions; +55.3G instructions] or [-18.664%; +60.300%]
  • unstable max_rss_usage [-6.039MB; +19.666MB] or [-3.695%; +12.035%]
  • unstable throughput [-1283.790op/s; +425.914op/s] or [-43.433%; +14.409%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-371.428ms; +286.629ms] or [-7.803%; +6.022%]
  • unstable execution_time [-372.635ms; +286.674ms] or [-7.705%; +5.927%]
  • unstable throughput [-98763.227op/s; +127822.426op/s] or [-5.692%; +7.367%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-48.108MB; +8.933MB] or [-12.591%; +2.338%]

scenario:plugin-graphql-long-with-depth-off-20

  • unstable max_rss_usage [-4.143MB; +9.715MB] or [-3.202%; +7.510%]

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

  • unstable max_rss_usage [-52.869MB; +73.324MB] or [-25.957%; +36.000%]

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.69%. Comparing base (27dcc31) to head (8717cf0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9120   +/-   ##
=======================================
  Coverage   93.69%   93.69%           
=======================================
  Files         889      889           
  Lines       50856    50860    +4     
  Branches    11830    11833    +3     
=======================================
+ Hits        47647    47651    +4     
  Misses       3209     3209           
Flag Coverage Δ
aiguard 34.87% <16.66%> (-0.09%) ⬇️
aiguard-integration 41.79% <ø> (ø)
apm-bucket-0 34.84% <16.66%> (-0.09%) ⬇️
apm-bucket-1 40.33% <16.66%> (-0.08%) ⬇️
apm-bucket-2 37.34% <16.66%> (-0.08%) ⬇️
apm-capabilities-tracing 48.30% <100.00%> (+<0.01%) ⬆️
apm-integrations-aerospike 33.12% <16.66%> (-0.09%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.03% <83.33%> (-0.08%) ⬇️
apm-integrations-couchbase 33.40% <16.66%> (-0.20%) ⬇️
apm-integrations-http 42.03% <16.66%> (-0.08%) ⬇️
apm-integrations-kafkajs 40.27% <83.33%> (-0.08%) ⬇️
apm-integrations-next 29.50% <16.66%> (-0.08%) ⬇️
apm-integrations-prisma 35.03% <16.66%> (-0.08%) ⬇️
apm-integrations-tedious 33.89% <16.66%> (-0.09%) ⬇️
appsec 57.30% <16.66%> (-0.15%) ⬇️
appsec-express_fastify_graphql 53.75% <16.66%> (-0.05%) ⬇️
appsec-integration 36.25% <ø> (ø)
appsec-kafka_ldapjs_lodash 43.67% <16.66%> (+0.01%) ⬆️
appsec-mongodb-core_mongoose_mysql 48.81% <16.66%> (-0.07%) ⬇️
appsec-next 28.00% <16.66%> (-0.08%) ⬇️
appsec-node-serialize_passport_postgres 48.04% <16.66%> (-0.02%) ⬇️
appsec-sourcing_stripe_template 45.55% <16.66%> (-0.07%) ⬇️
debugger 44.37% <ø> (-0.05%) ⬇️
instrumentations-bucket-0 28.15% <16.66%> (-0.09%) ⬇️
instrumentations-bucket-1 37.40% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-10 40.43% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-11 27.95% <16.66%> (-0.09%) ⬇️
instrumentations-bucket-12 28.66% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-13 27.78% <16.66%> (-0.09%) ⬇️
instrumentations-bucket-2 30.23% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-3 35.90% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-4 28.06% <16.66%> (-0.09%) ⬇️
instrumentations-bucket-5 36.28% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-6 38.25% <16.66%> (-0.09%) ⬇️
instrumentations-bucket-7 36.00% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-8 36.95% <16.66%> (-0.08%) ⬇️
instrumentations-bucket-9 39.53% <16.66%> (-0.08%) ⬇️
instrumentations-instrumentation-couchbase 46.54% <ø> (ø)
instrumentations-integration-esbuild 24.87% <ø> (ø)
llmobs-ai_anthropic_bedrock 39.53% <16.66%> (-0.07%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.85% <16.66%> (-0.19%) ⬇️
llmobs-openai 39.58% <16.66%> (-0.08%) ⬇️
llmobs-sdk 43.59% <16.66%> (-0.09%) ⬇️
master-coverage 93.69% <100.00%> (?)
openfeature 37.76% <ø> (ø)
openfeature-unit 50.39% <ø> (ø)
platform-core_esbuild_instrumentations-misc 23.36% <ø> (ø)
platform-integration 47.44% <ø> (+0.01%) ⬆️
platform-shimmer_unit-guardrails_webpack 18.89% <ø> (ø)
plugins-bucket-0 36.33% <16.66%> (-0.08%) ⬇️
plugins-bucket-1 39.61% <ø> (ø)
plugins-bucket-11 38.46% <16.66%> (-0.08%) ⬇️
plugins-bucket-17 39.05% <16.66%> (-0.19%) ⬇️
plugins-bucket-18 42.00% <33.33%> (-0.08%) ⬇️
plugins-bucket-19 39.56% <16.66%> (-0.08%) ⬇️
plugins-bucket-20 43.25% <33.33%> (-0.12%) ⬇️
plugins-bucket-4 37.71% <16.66%> (-0.08%) ⬇️
plugins-bullmq_cassandra_cookie 39.76% <33.33%> (-0.08%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.22% <16.66%> (-0.09%) ⬇️
plugins-fetch_fs_generic-pool 36.05% <16.66%> (-0.09%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.09% <33.33%> (-0.09%) ⬇️
plugins-hapi_hono_ioredis 37.78% <16.66%> (-0.08%) ⬇️
plugins-jest_knex_langgraph 32.60% <16.66%> (-0.09%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.85% <16.66%> (-0.09%) ⬇️
plugins-lodash_mariadb_memcached 35.17% <16.66%> (-0.09%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.31% <16.66%> (-0.08%) ⬇️
plugins-multer_mysql_mysql2 35.14% <16.66%> (-0.09%) ⬇️
plugins-nats_node-serialize_opensearch 37.15% <16.66%> (-0.08%) ⬇️
plugins-passport-http_pino_postgres 35.53% <16.66%> (-0.09%) ⬇️
plugins-process_pug_redis 34.26% <16.66%> (-0.09%) ⬇️
plugins-undici_url_valkey 35.88% <16.66%> (-0.08%) ⬇️
plugins-vm_winston_ws 37.55% <16.66%> (-0.09%) ⬇️
profiling 43.62% <ø> (-0.07%) ⬇️
serverless-aws-sdk-aws-sdk 33.20% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-bedrockruntime 32.06% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-client 37.21% <ø> (ø)
serverless-aws-sdk-dynamodb 34.05% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-eventbridge 27.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.40% <33.33%> (-0.08%) ⬇️
serverless-aws-sdk-lambda 34.50% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-s3 32.50% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.45% <33.33%> (-0.10%) ⬇️
serverless-aws-sdk-sns 38.25% <33.33%> (-0.21%) ⬇️
serverless-aws-sdk-sqs 37.99% <33.33%> (-0.08%) ⬇️
serverless-aws-sdk-stepfunctions 33.08% <16.66%> (-0.17%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.47% <ø> (ø)
serverless-lambda 34.32% <16.66%> (-0.10%) ⬇️
test-optimization-cucumber 52.57% <ø> (+0.11%) ⬆️
test-optimization-cypress 49.62% <ø> (+0.07%) ⬆️
test-optimization-jest 55.67% <ø> (+0.11%) ⬆️
test-optimization-mocha 53.66% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-atr 43.59% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.87% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.93% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.41% <ø> (ø)
test-optimization-playwright-playwright-reporting 43.50% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 45.16% <ø> (+0.31%) ⬆️
test-optimization-playwright-playwright-test-span 44.78% <ø> (+0.07%) ⬆️
test-optimization-selenium 45.52% <ø> (+0.06%) ⬆️
test-optimization-testopt 48.28% <ø> (+0.08%) ⬆️
test-optimization-vitest 50.93% <ø> (+0.10%) ⬆️

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.

@BridgeAR
BridgeAR merged commit f3c7006 into master Jul 2, 2026
1075 of 1078 checks passed
@BridgeAR
BridgeAR deleted the BridgeAR/2026-06-27-fix-amqplib-dsm-flake branch July 2, 2026 15:29
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jul 2, 2026
dd-octo-sts Bot pushed a commit that referenced this pull request Jul 2, 2026
With `flushInterval: 0` (the test-agent config and the AWS Lambda config) the
processor armed `setInterval(onInterval, 0)`, which fires on every event-loop
tick instead of when a checkpoint is recorded. A tick landing in the window
between the test agent tearing its listener down and bringing it back up posts
to a dead port; the bucket is cleared on serialize, so that single payload is
lost. A producer-only DSM test waiting on exactly one payload then times out.

Honor `flushInterval === 0` as the flush-on-write sentinel the agent and
agentless trace exporters already use: skip the timer and push each checkpoint,
offset, and transaction the moment it is recorded, while the writer URL is live.
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jul 2, 2026
rochdev pushed a commit that referenced this pull request Jul 2, 2026
With `flushInterval: 0` (the test-agent config and the AWS Lambda config) the
processor armed `setInterval(onInterval, 0)`, which fires on every event-loop
tick instead of when a checkpoint is recorded. A tick landing in the window
between the test agent tearing its listener down and bringing it back up posts
to a dead port; the bucket is cleared on serialize, so that single payload is
lost. A producer-only DSM test waiting on exactly one payload then times out.

Honor `flushInterval === 0` as the flush-on-write sentinel the agent and
agentless trace exporters already use: skip the timer and push each checkpoint,
offset, and transaction the moment it is recorded, while the writer URL is live.
rochdev pushed a commit that referenced this pull request Jul 2, 2026
With `flushInterval: 0` (the test-agent config and the AWS Lambda config) the
processor armed `setInterval(onInterval, 0)`, which fires on every event-loop
tick instead of when a checkpoint is recorded. A tick landing in the window
between the test agent tearing its listener down and bringing it back up posts
to a dead port; the bucket is cleared on serialize, so that single payload is
lost. A producer-only DSM test waiting on exactly one payload then times out.

Honor `flushInterval === 0` as the flush-on-write sentinel the agent and
agentless trace exporters already use: skip the timer and push each checkpoint,
offset, and transaction the moment it is recorded, while the writer URL is live.
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.

2 participants