Skip to content

refactor(vitest): split main and worker instrumentation#9170

Merged
juan-fernandez merged 1 commit into
masterfrom
juan-fernandez/vitest-split-main-worker
Jul 1, 2026
Merged

refactor(vitest): split main and worker instrumentation#9170
juan-fernandez merged 1 commit into
masterfrom
juan-fernandez/vitest-split-main-worker

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Splits the Vitest instrumentation into process-specific modules on top of #9169:

  • vitest.js is now a small dispatcher that loads the worker module when DD_VITEST_WORKER=1, otherwise the main-process module.
  • vitest-main.js owns session setup/finish, sequencer wrapping, coverage wrapping, Tinypool and Vitest pool worker setup, and worker-report handling.
  • vitest-worker.js owns @vitest/runner hooks, test/test-suite lifecycle publication, retry handling, EFD, Test Management, and Failed Test Replay worker behavior.
  • vitest-util.js contains shared channels and small Vitest helper functions used by both sides.

Motivation

With #9169 making DD_VITEST_WORKER reliably available for every supported Vitest worker, the instrumentation now has a stable boundary between main-process hooks and worker-process hooks. Splitting the file makes that boundary explicit and keeps future changes from mixing worker test lifecycle behavior with main-process worker transport setup.

@dd-octo-sts

dd-octo-sts Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.43 MB
Deduped: 7.49 MB
No deduping: 7.49 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-prod-us1-3

datadog-prod-us1-3 Bot commented Jul 1, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 78.61%
Overall Coverage: 88.02% (+0.00%)

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

@pr-commenter

pr-commenter Bot commented Jul 1, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-01 10:43:55

Comparing candidate commit 2476014 in PR branch juan-fernandez/vitest-split-main-worker with baseline commit dd01d58 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2255 metrics, 31 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 [-185.558ms; +176.783ms] or [-7.039%; +6.706%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-209.149ms; +204.182ms] or [-8.325%; +8.127%]

scenario:appsec-control-20

  • unstable execution_time [-163.735ms; +167.205ms] or [-9.369%; +9.567%]

scenario:appsec-control-24

  • unstable execution_time [-99836.419µs; +99037.352µs] or [-8.213%; +8.147%]

scenario:appsec-control-26

  • unstable execution_time [-114328.374µs; +114798.374µs] or [-9.469%; +9.508%]

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

  • unstable cpu_user_time [-2.073s; +4.626s] or [-20.744%; +46.293%]
  • unstable execution_time [-2.097s; +4.659s] or [-19.608%; +43.565%]
  • unstable instructions [-18.7G instructions; +41.1G instructions] or [-22.466%; +49.270%]
  • unstable max_rss_usage [-6.909MB; +14.187MB] or [-4.293%; +8.815%]
  • unstable throughput [-1013.948op/s; +445.934op/s] or [-32.431%; +14.263%]

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

  • unstable cpu_user_time [-1.945s; +4.195s] or [-22.909%; +49.407%]
  • unstable execution_time [-1.977s; +4.257s] or [-21.569%; +46.448%]
  • unstable instructions [-16.9G instructions; +36.4G instructions] or [-24.390%; +52.449%]
  • unstable max_rss_usage [-7.385MB; +15.582MB] or [-4.610%; +9.728%]
  • unstable throughput [-1250.604op/s; +580.702op/s] or [-34.035%; +15.804%]

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

  • unstable cpu_user_time [-2.862s; +0.443s] or [-28.746%; +4.450%]
  • unstable execution_time [-2.877s; +0.465s] or [-27.034%; +4.372%]
  • unstable instructions [-25.2G instructions; +3.8G instructions] or [-30.246%; +4.574%]
  • unstable throughput [-115.199op/s; +616.632op/s] or [-3.659%; +19.584%]

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

  • unstable cpu_user_time [-3.046s; +6.347s] or [-29.392%; +61.232%]
  • unstable execution_time [-3.122s; +6.429s] or [-28.220%; +58.121%]
  • unstable instructions [-18.7G instructions; +41.5G instructions] or [-22.405%; +49.750%]
  • unstable max_rss_usage [-7.013MB; +15.427MB] or [-4.379%; +9.634%]
  • unstable throughput [-1195.241op/s; +567.993op/s] or [-38.559%; +18.323%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-457.542ms; +235.553ms] or [-9.471%; +4.876%]
  • unstable execution_time [-456.712ms; +235.811ms] or [-9.310%; +4.807%]
  • unstable throughput [-82594.061op/s; +155808.801op/s] or [-4.821%; +9.094%]

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

  • unstable max_rss_usage [-18.000MB; +32.973MB] or [-4.882%; +8.943%]

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

  • unstable max_rss_usage [-7.877MB; +5.708MB] or [-6.080%; +4.406%]

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

  • unstable max_rss_usage [-25.732MB; +9.870MB] or [-13.408%; +5.143%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-4453.435KB; +6261.768KB] or [-5.548%; +7.800%]

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.03320% with 125 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.72%. Comparing base (dd01d58) to head (2476014).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ckages/datadog-instrumentations/src/vitest-main.js 78.81% 100 Missing ⚠️
...ages/datadog-instrumentations/src/vitest-worker.js 94.60% 22 Missing ⚠️
...ckages/datadog-instrumentations/src/vitest-util.js 96.20% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (87.03%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9170   +/-   ##
=======================================
  Coverage   93.71%   93.72%           
=======================================
  Files         892      895    +3     
  Lines       51311    51324   +13     
  Branches    11945    11947    +2     
=======================================
+ Hits        48087    48101   +14     
+ Misses       3224     3223    -1     
Flag Coverage Δ
aiguard 34.87% <ø> (-0.08%) ⬇️
aiguard-integration 41.79% <ø> (ø)
apm-bucket-0 34.84% <ø> (-0.08%) ⬇️
apm-bucket-1 40.33% <ø> (-0.07%) ⬇️
apm-bucket-2 37.34% <ø> (-0.07%) ⬇️
apm-capabilities-tracing 48.68% <ø> (ø)
apm-integrations-aerospike 33.12% <ø> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.02% <ø> (-0.08%) ⬇️
apm-integrations-couchbase 33.24% <ø> (-0.24%) ⬇️
apm-integrations-http 41.95% <ø> (-0.07%) ⬇️
apm-integrations-kafkajs 40.30% <ø> (-0.04%) ⬇️
apm-integrations-next 29.46% <ø> (-0.11%) ⬇️
apm-integrations-prisma 35.03% <ø> (-0.07%) ⬇️
apm-integrations-tedious 33.89% <ø> (-0.08%) ⬇️
appsec 57.67% <ø> (-0.08%) ⬇️
appsec-express_fastify_graphql 53.66% <ø> (-0.05%) ⬇️
appsec-integration 36.57% <12.94%> (+0.38%) ⬆️
appsec-kafka_ldapjs_lodash 43.58% <ø> (-0.07%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.74% <ø> (-0.06%) ⬇️
appsec-next 28.00% <ø> (-0.07%) ⬇️
appsec-node-serialize_passport_postgres 47.91% <ø> (-0.11%) ⬇️
appsec-sourcing_stripe_template 45.47% <ø> (-0.06%) ⬇️
debugger 44.42% <ø> (+0.04%) ⬆️
instrumentations-bucket-0 28.15% <ø> (-0.08%) ⬇️
instrumentations-bucket-1 37.40% <ø> (-0.07%) ⬇️
instrumentations-bucket-10 40.35% <ø> (-0.07%) ⬇️
instrumentations-bucket-11 27.95% <ø> (-0.08%) ⬇️
instrumentations-bucket-12 28.67% <ø> (-0.08%) ⬇️
instrumentations-bucket-13 27.78% <ø> (-0.08%) ⬇️
instrumentations-bucket-2 30.23% <ø> (-0.07%) ⬇️
instrumentations-bucket-3 35.90% <ø> (-0.07%) ⬇️
instrumentations-bucket-4 28.56% <ø> (-0.08%) ⬇️
instrumentations-bucket-5 36.28% <ø> (-0.07%) ⬇️
instrumentations-bucket-6 38.25% <ø> (-0.08%) ⬇️
instrumentations-bucket-7 35.92% <ø> (-0.16%) ⬇️
instrumentations-bucket-8 36.95% <ø> (-0.07%) ⬇️
instrumentations-bucket-9 39.45% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.48% <ø> (ø)
instrumentations-integration-esbuild 25.15% <12.94%> (+0.26%) ⬆️
llmobs-ai_anthropic_bedrock 39.53% <ø> (-0.07%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.97% <ø> (-0.06%) ⬇️
llmobs-openai 39.58% <ø> (-0.07%) ⬇️
llmobs-sdk 43.59% <ø> (-0.08%) ⬇️
master-coverage 93.72% <87.03%> (?)
openfeature 37.76% <ø> (ø)
openfeature-unit 50.39% <ø> (ø)
platform-core_esbuild_instrumentations-misc 23.59% <12.94%> (+0.26%) ⬆️
platform-integration 47.42% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 19.13% <12.94%> (+0.24%) ⬆️
plugins-bucket-0 36.37% <ø> (-0.07%) ⬇️
plugins-bucket-1 39.60% <ø> (ø)
plugins-bucket-11 38.46% <ø> (-0.08%) ⬇️
plugins-bucket-17 39.15% <ø> (-0.07%) ⬇️
plugins-bucket-18 42.01% <ø> (-0.07%) ⬇️
plugins-bucket-19 39.56% <ø> (-0.07%) ⬇️
plugins-bucket-20 43.25% <ø> (-0.07%) ⬇️
plugins-bucket-4 37.71% <ø> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.76% <ø> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.22% <ø> (-0.08%) ⬇️
plugins-fetch_fs_generic-pool 36.05% <ø> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.10% <ø> (-0.07%) ⬇️
plugins-hapi_hono_ioredis 37.78% <ø> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.60% <ø> (-0.08%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.85% <ø> (-0.08%) ⬇️
plugins-lodash_mariadb_memcached 35.17% <ø> (-0.08%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.31% <ø> (-0.07%) ⬇️
plugins-multer_mysql_mysql2 35.14% <ø> (-0.08%) ⬇️
plugins-nats_node-serialize_opensearch 37.14% <ø> (-0.08%) ⬇️
plugins-passport-http_pino_postgres 35.53% <ø> (-0.08%) ⬇️
plugins-process_pug_redis 34.26% <ø> (-0.08%) ⬇️
plugins-undici_url_valkey 35.88% <ø> (-0.08%) ⬇️
plugins-vm_winston_ws 37.55% <ø> (-0.08%) ⬇️
profiling 43.62% <ø> (-0.07%) ⬇️
serverless-aws-sdk-aws-sdk 33.29% <ø> (-0.07%) ⬇️
serverless-aws-sdk-bedrockruntime 32.16% <ø> (-0.07%) ⬇️
serverless-aws-sdk-client 37.16% <ø> (ø)
serverless-aws-sdk-dynamodb 34.09% <ø> (-0.12%) ⬇️
serverless-aws-sdk-eventbridge 27.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.40% <ø> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.59% <ø> (-0.07%) ⬇️
serverless-aws-sdk-s3 32.59% <ø> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.47% <ø> (-0.08%) ⬇️
serverless-aws-sdk-sns 38.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-sqs 38.00% <ø> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.18% <ø> (-0.07%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.46% <ø> (ø)
serverless-lambda 34.33% <ø> (-0.09%) ⬇️
test-optimization-cucumber 52.30% <ø> (+0.11%) ⬆️
test-optimization-cypress 49.41% <ø> (+0.06%) ⬆️
test-optimization-jest 55.34% <ø> (+0.04%) ⬆️
test-optimization-mocha 53.38% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-atr 43.33% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-efd 43.61% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-final-status 43.73% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.16% <ø> (ø)
test-optimization-playwright-playwright-reporting 43.26% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-management 44.72% <ø> (+0.08%) ⬆️
test-optimization-playwright-playwright-test-span 44.51% <ø> (+0.07%) ⬆️
test-optimization-selenium 45.26% <ø> (+0.06%) ⬆️
test-optimization-testopt 48.02% <26.03%> (+0.12%) ⬆️
test-optimization-vitest 50.73% <86.61%> (+0.14%) ⬆️

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.

@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/vitest-split-main-worker branch from 634acea to e6abd9f Compare July 1, 2026 10:17
Base automatically changed from juan-fernandez/vitest-worker-exporter-threads to master July 1, 2026 10:30
@juan-fernandez
juan-fernandez force-pushed the juan-fernandez/vitest-split-main-worker branch from e6abd9f to 2476014 Compare July 1, 2026 10:33
@juan-fernandez
juan-fernandez marked this pull request as ready for review July 1, 2026 10:35
@juan-fernandez
juan-fernandez requested review from a team as code owners July 1, 2026 10:35
@juan-fernandez
juan-fernandez requested review from wconti27 and removed request for a team July 1, 2026 10:35
@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2476014f26

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@juan-fernandez
juan-fernandez merged commit 79b87ef into master Jul 1, 2026
848 of 849 checks passed
@juan-fernandez
juan-fernandez deleted the juan-fernandez/vitest-split-main-worker branch July 1, 2026 10:46

@datadog-prod-us1-3 datadog-prod-us1-3 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.

Datadog Autotest: PASS

More details

All 15 addHook registrations from the original vitest.js are accounted for (11 in vitest-main.js, 4 in vitest-worker.js). Channel identity is preserved via Node.js module caching of vitest-util.js, and realSetTimeout is captured at line 4 of vitest-worker.js before any test can install fake timers. 26 adversarial scenarios covering isFlakyTestRetriesEnabledForTask, getTypeTasks, getTestName, getProvidedContext failure paths, and dispatcher routing all passed cleanly.

Was this helpful? React 👍 or 👎

📊 Validated against 26 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 2476014 · What is Autotest? · Any feedback? Reach out in #autotest

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