Skip to content

fix(tracing): make peer service finalization idempotent#9364

Open
BridgeAR wants to merge 6 commits into
masterfrom
BridgeAR/2026-07-14-fix-mongoose-peer-service-flake
Open

fix(tracing): make peer service finalization idempotent#9364
BridgeAR wants to merge 6 commits into
masterfrom
BridgeAR/2026-07-14-fix-mongoose-peer-service-flake

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

Summary

Peer-service checks now arm the agent expectation before starting the operation and match across every span in a payload. The previous order plus the traces[0][0] assumption let MongoDB connection spans hide the expected operation span, causing the mongoose test to time out intermittently.

@dd-octo-sts

dd-octo-sts Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 7.47 MB
Deduped: 8.14 MB
No deduping: 8.14 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.2 | 124.41 kB | 440.65 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 Jul 15, 2026

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

🚦 2 Pipeline jobs failed

All Green | all-green   View in Datadog   GitHub Actions

Platform | integration-guardrails (22.0.0)   View in Datadog   GitHub Actions

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

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

Useful? React with 👍 / 👎

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

@pr-commenter

pr-commenter Bot commented Jul 15, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-21 11:20:16

Comparing candidate commit ea19d7d in PR branch BridgeAR/2026-07-14-fix-mongoose-peer-service-flake with baseline commit c8e8699 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2322 metrics, 36 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 execution_time [-208823.160µs; +208877.360µs] or [-7.833%; +7.835%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-233.774ms; +235.979ms] or [-9.130%; +9.217%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-160.807ms; +153.831ms] or [-5.200%; +4.975%]

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

  • unstable execution_time [-184.868ms; +142.025ms] or [-6.392%; +4.911%]

scenario:appsec-control-20

  • unstable execution_time [-116.813ms; +130.604ms] or [-7.056%; +7.889%]

scenario:appsec-control-24

  • unstable execution_time [-113.938ms; +110.845ms] or [-9.168%; +8.919%]

scenario:appsec-control-26

  • unstable execution_time [-125.856ms; +130.319ms] or [-10.160%; +10.521%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-18.877ms; +15.305ms] or [-7.300%; +5.919%]

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

  • unstable execution_time [-29.338ms; +27.250ms] or [-5.315%; +4.936%]

scenario:child_process-shell-string-24

  • unstable execution_time [-13.586ms; +20.641ms] or [-4.286%; +6.513%]

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

  • unstable cpu_user_time [-4.616s; +0.011s] or [-41.601%; +0.099%]
  • unstable execution_time [-4.632s; -0.007s] or [-39.072%; -0.062%]
  • unstable instructions [-45.2G instructions; -0.4G instructions] or [-47.318%; -0.416%]
  • unstable throughput [-0.044op/s; +907.151op/s] or [-0.002%; +31.149%]

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

  • unstable cpu_user_time [-1512.211ms; +501.960ms] or [-18.413%; +6.112%]
  • unstable execution_time [-1530.366ms; +496.981ms] or [-17.164%; +5.574%]
  • unstable instructions [-13.0G instructions; +4.2G instructions] or [-19.307%; +6.239%]
  • unstable throughput [-142.627op/s; +434.775op/s] or [-3.882%; +11.833%]

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

  • unstable cpu_user_time [-3576.344ms; +5114.344ms] or [-32.177%; +46.014%]
  • unstable execution_time [-3554.359ms; +5107.226ms] or [-29.991%; +43.093%]
  • unstable instructions [-31.8G instructions; +45.7G instructions] or [-34.058%; +48.965%]
  • unstable max_rss_usage [-11.555MB; +17.399MB] or [-7.058%; +10.627%]
  • unstable throughput [-997.794op/s; +688.889op/s] or [-34.269%; +23.660%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-234.970ms; +461.874ms] or [-4.940%; +9.710%]
  • unstable execution_time [-232.244ms; +471.363ms] or [-4.807%; +9.756%]
  • unstable throughput [-167032.280op/s; +83802.097op/s] or [-9.608%; +4.820%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-4.186%; +6.067%]

scenario:plugin-claude-agent-sdk-delayed-noisy-hook-indexed-26

  • unstable execution_time [-10.793ms; +17.655ms] or [-3.835%; +6.273%]

scenario:plugin-couchbase-upsert-26

  • unstable cpu_user_time [-182.979ms; +309.882ms] or [-4.122%; +6.982%]
  • unstable execution_time [-176.464ms; +303.426ms] or [-3.832%; +6.589%]

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

  • unstable max_rss_usage [-36.802MB; +18.067MB] or [-16.960%; +8.326%]

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

  • unstable cpu_user_time [-605.345ms; +578.673ms] or [-5.259%; +5.027%]
  • unstable execution_time [-613.940ms; +586.969ms] or [-5.226%; +4.997%]
  • unstable throughput [-3.432op/s; +3.615op/s] or [-5.010%; +5.278%]

scenario:plugin-pg-service-26

  • unstable execution_time [-48311.369µs; +50092.769µs] or [-5.387%; +5.586%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-4263.760KB; +4204.427KB] or [-5.426%; +5.351%]

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.42%. Comparing base (c8e8699) to head (ea19d7d).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #9364    +/-   ##
========================================
  Coverage   98.42%   98.42%            
========================================
  Files         938      938            
  Lines      126209   126212     +3     
  Branches    10735    10849   +114     
========================================
+ Hits       124219   124222     +3     
  Misses       1990     1990            
Flag Coverage Δ
aiguard 57.79% <0.00%> (-0.03%) ⬇️
aiguard-integration 56.23% <0.00%> (-0.01%) ⬇️
apm-bucket-0 57.65% <100.00%> (-0.03%) ⬇️
apm-bucket-1 63.72% <100.00%> (-0.02%) ⬇️
apm-bucket-2 62.74% <100.00%> (-0.02%) ⬇️
apm-bucket-3 60.18% <100.00%> (+0.05%) ⬆️
apm-capabilities-tracing 64.20% <100.00%> (+<0.01%) ⬆️
apm-integrations-aerospike 56.74% <100.00%> (+0.06%) ⬆️
apm-integrations-confluentinc-kafka-javascript 61.62% <100.00%> (-0.03%) ⬇️
apm-integrations-couchbase 57.08% <0.00%> (-0.03%) ⬇️
apm-integrations-http 62.79% <100.00%> (-0.02%) ⬇️
apm-integrations-kafkajs 62.24% <100.00%> (+0.03%) ⬆️
apm-integrations-next 59.20% <0.00%> (-0.03%) ⬇️
apm-integrations-prisma 58.68% <100.00%> (-0.02%) ⬇️
appsec 72.97% <100.00%> (-0.04%) ⬇️
appsec-express_fastify_graphql 70.45% <100.00%> (-0.02%) ⬇️
appsec-integration 51.43% <0.00%> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 63.99% <100.00%> (-0.02%) ⬇️
appsec-mongodb-core_mongoose_mysql 67.73% <100.00%> (-0.02%) ⬇️
appsec-next 57.52% <100.00%> (-0.02%) ⬇️
appsec-node-serialize_passport_postgres 67.40% <100.00%> (-0.02%) ⬇️
appsec-sourcing_stripe_template 65.74% <100.00%> (-0.02%) ⬇️
debugger 64.98% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-0 51.61% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-1 60.21% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-10 61.79% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-11 56.68% <100.00%> (-0.03%) ⬇️
instrumentations-bucket-12 51.94% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-13 51.98% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-2 53.28% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-3 53.57% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-4 59.20% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-5 49.98% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-6 60.94% <100.00%> (-0.03%) ⬇️
instrumentations-bucket-7 58.36% <0.00%> (-0.03%) ⬇️
instrumentations-bucket-8 59.45% <100.00%> (-0.02%) ⬇️
instrumentations-bucket-9 51.99% <0.00%> (-0.03%) ⬇️
instrumentations-instrumentation-couchbase 51.04% <0.00%> (-0.03%) ⬇️
instrumentations-instrumentation-zlib 51.61% <0.00%> (-0.03%) ⬇️
instrumentations-integration-esbuild 34.12% <0.00%> (-0.01%) ⬇️
llmobs-ai_anthropic_bedrock 62.58% <100.00%> (-0.02%) ⬇️
llmobs-bucket-1 61.84% <100.00%> (-0.02%) ⬇️
llmobs-openai 62.71% <100.00%> (-0.02%) ⬇️
llmobs-sdk 66.22% <0.00%> (-0.03%) ⬇️
llmobs-vertex-ai 59.18% <0.00%> (-0.03%) ⬇️
master-coverage 98.42% <100.00%> (?)
openfeature 53.97% <0.00%> (-0.01%) ⬇️
openfeature-unit 52.72% <0.00%> (-0.03%) ⬇️
platform-core_esbuild_instrumentations-misc 40.36% <0.00%> (-0.02%) ⬇️
platform-integration 61.50% <0.00%> (-0.01%) ⬇️
platform-shimmer_unit-guardrails_webpack 39.06% <0.00%> (-0.02%) ⬇️
plugins-bucket-0 57.06% <100.00%> (-0.02%) ⬇️
plugins-bucket-1 54.43% <0.00%> (-0.01%) ⬇️
plugins-bucket-11 62.29% <0.00%> (-0.03%) ⬇️
plugins-bucket-18 62.09% <100.00%> (-0.02%) ⬇️
plugins-bucket-19 60.09% <0.00%> (-0.03%) ⬇️
plugins-bucket-20 62.06% <0.00%> (-0.03%) ⬇️
plugins-bucket-4 58.59% <0.00%> (-0.03%) ⬇️
plugins-bullmq_cassandra_cookie 61.80% <100.00%> (-0.02%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 56.74% <0.00%> (-0.03%) ⬇️
plugins-fetch_fs_generic-pool 58.82% <100.00%> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 64.76% <100.00%> (-0.02%) ⬇️
plugins-hapi_hono_ioredis 60.27% <100.00%> (-0.02%) ⬇️
plugins-jest_knex_langgraph 55.60% <0.00%> (-0.03%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 58.52% <100.00%> (-0.04%) ⬇️
plugins-lodash_mariadb_memcached 58.11% <100.00%> (+0.06%) ⬆️
plugins-moleculer_mongodb_mongodb-core 61.97% <100.00%> (-0.02%) ⬇️
plugins-mongoose_multer_mysql 59.11% <100.00%> (+0.04%) ⬆️
plugins-mysql2_nats_node-serialize 60.76% <100.00%> (-0.03%) ⬇️
plugins-opensearch_passport-http_pino 59.58% <100.00%> (-0.02%) ⬇️
plugins-postgres_process_pug 58.30% <100.00%> (-0.03%) ⬇️
plugins-redis_router_sequelize 62.15% <100.00%> (+0.03%) ⬆️
plugins-test-and-upstream-rhea_undici_url 61.70% <100.00%> (-0.02%) ⬇️
plugins-valkey_vm_winston 58.03% <100.00%> (-0.02%) ⬇️
plugins-ws 59.61% <0.00%> (-0.03%) ⬇️
profiling 62.22% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-aws-sdk 55.08% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-bedrockruntime 54.77% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-client 56.44% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-dynamodb 55.68% <100.00%> (-0.03%) ⬇️
serverless-aws-sdk-eventbridge 49.38% <0.00%> (-0.03%) ⬇️
serverless-aws-sdk-kinesis 59.39% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-lambda 57.42% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-s3 55.78% <100.00%> (+0.13%) ⬆️
serverless-aws-sdk-serverless-peer-service 59.79% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-sns 60.25% <100.00%> (+0.04%) ⬆️
serverless-aws-sdk-sqs 60.67% <100.00%> (+0.03%) ⬆️
serverless-aws-sdk-stepfunctions 55.60% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-util 51.49% <0.00%> (-0.03%) ⬇️
serverless-bucket-0 54.31% <0.00%> (-0.01%) ⬇️
serverless-bucket-1 59.28% <0.00%> (-0.03%) ⬇️
test-optimization-cucumber 71.77% <0.00%> (-0.01%) ⬇️
test-optimization-cypress 65.79% <0.00%> (+0.06%) ⬆️
test-optimization-jest 73.30% <0.00%> (+<0.01%) ⬆️
test-optimization-mocha 73.46% <0.00%> (+0.04%) ⬆️
test-optimization-playwright-playwright-atr 60.41% <0.00%> (-0.02%) ⬇️
test-optimization-playwright-playwright-efd 60.60% <0.00%> (-0.01%) ⬇️
test-optimization-playwright-playwright-final-status 60.64% <0.00%> (+0.05%) ⬆️
test-optimization-playwright-playwright-impacted-tests 60.30% <0.00%> (+0.15%) ⬆️
test-optimization-playwright-playwright-reporting 60.20% <0.00%> (-0.02%) ⬇️
test-optimization-playwright-playwright-test-management 60.90% <0.00%> (-0.12%) ⬇️
test-optimization-playwright-playwright-test-span 60.33% <0.00%> (-0.07%) ⬇️
test-optimization-selenium 59.82% <0.00%> (-0.17%) ⬇️
test-optimization-testopt 58.46% <0.00%> (+0.08%) ⬆️
test-optimization-vitest 70.22% <0.00%> (+<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.

@BridgeAR
BridgeAR marked this pull request as ready for review July 15, 2026 08:42
@BridgeAR
BridgeAR requested a review from a team as a code owner July 15, 2026 08:42

@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: 236933d494

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

Comment thread packages/dd-trace/test/setup/mocha.js Outdated
Comment thread packages/dd-trace/test/setup/mocha.js Outdated
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-07-14-fix-mongoose-peer-service-flake branch from 236933d to ce891eb Compare July 16, 2026 01:11
@BridgeAR
BridgeAR marked this pull request as draft July 16, 2026 14:32
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-07-14-fix-mongoose-peer-service-flake branch from ce891eb to cbdade2 Compare July 20, 2026 19:03
@BridgeAR BridgeAR changed the title test: stop peer service checks racing operation spans fix(tracing): make peer service finalization idempotent Jul 20, 2026
@BridgeAR
BridgeAR marked this pull request as ready for review July 20, 2026 23:51
@BridgeAR
BridgeAR requested a review from a team as a code owner July 20, 2026 23:51
@BridgeAR
BridgeAR requested review from wconti27 and removed request for a team July 20, 2026 23:51

@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: 3dc4c7b306

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

Comment thread packages/dd-trace/test/setup/mocha.js
BridgeAR added 6 commits July 21, 2026 13:02
The shared helper started the operation before registering its trace expectation and only inspected the first span of each payload. MongoDB connection traffic could therefore consume the payload containing the expected operation span, leaving the test to time out.
Delayed setup traces can carry the same peer-service tags as the operation under test, allowing the shared matcher to pass without observing that operation. Run each generator under a unique parent and match its child span instead.

Generator throws and invalid return values can bypass assertion cleanup. Keep the whole operation inside the cleanup boundary so the original failure is not replaced by a leaked-expectation teardown error.
Peer-service spans can be nested below integration spans, so requiring a direct parent excluded valid operations. Match the generated trace to keep setup traffic isolated without constraining span depth.
Keeping the correlation parent open until the operation settled delayed trace export. Integrations that publish duplicate finish notifications could then recompute `_dd.peer.service.source` before the trace was sent.
Repeated finish notifications can reach an outbound span before an ancestor lets the trace flush. The second pass treats the computed peer service as preconfigured and rewrites its source to `peer.service`; an existing source now marks finalization.

The peer-service assertion keeps its correlation parent open through completion and matches the integration component, so delayed setup traces and spans from another integration cannot satisfy it.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-07-14-fix-mongoose-peer-service-flake branch from 3dc4c7b to ea19d7d Compare July 21, 2026 11:04
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