feat(graphql): add mercurius support with a top-level graphql.request span #9142
Overall package size
Self size: 6.68 MB
Deduped: 7.34 MB
No deduping: 7.34 MB
<details><summary>Dependency sizes</summary>
| name | version | self size | total size |
|------|---------|-----------|------------|
| import-in-the-middle | 3.3.1 | 122.62 kB | 437.94 kB |
| opentracing | 0.14.7 | 194.81 kB | 194.81 kB |
| dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |
</details>
<sub>🤖 This report was automatically generated by heaviest-objects-in-the-universe<sub>
<picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok-light.svg" alt="Tests" align="center" /></picture>
<details><summary><b>🎉 All green!</b></summary>
🧪 All tests passed
❄️ No new flaky tests detected
</details>
🎯 Code Coverage (<a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdd-trace-js/pull-requests/9142'>details</a>)<br>• <strong><span title="Percentage of modified executable lines covered by tests in this PR">Patch Coverage</span></strong>: 100.00%<br>• <strong><span title="Percentage of all executable lines covered by tests in the entire codebase">Overall Coverage</span></strong>: 96.51% <span title="Change in overall coverage compared to the base branch">(+0.01%)</span><br>
<sub>
This comment will be updated automatically if new data arrives. <br />
🔗 Commit SHA: b6c2dbe | <a href="https://docs.datadoghq.com/integrations/guide/source-code-integration/#pr-comments">Docs</a> | <a href="https://app.datadoghq.com/ci/pull-request/Z2l0aHViLmNvbS9kYXRhZG9nL2RkLXRyYWNlLWpzLzkxNDI=">Datadog PR Page</a> | Give us <a href="https://dd.enterprise.slack.com/archives/C07E3U2QRMM">feedback</a>!
</sub>
Benchmarks
Benchmark execution time: 2026-07-08 16:14:39
Comparing candidate commit b6c2dbe9eb3d15dadfdd107a2972fc6c7cedd5fc in PR branch BridgeAR/2026-06-29-mercurius with baseline commit 221c2fb40ddcfc58bc04dc92f84df776bfb8062d in branch master.
Found 0 performance improvements and 0 performance regressions! Performance is the same for 2311 metrics, 47 unstable metrics.
<details>
<summary><h3>Explanation</h3></summary>
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.
<details>
<summary><h4>More details about the CI and significant changes</h4></summary>
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 ----------------------------------'
</details>
</details>
<details>
<summary><h3>Unstable benchmarks</h3></summary>
These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.
scenario:appsec-appsec-enabled-24
execution_time [-209.791ms; +202.954ms] or [-7.865%; +7.608%]scenario:appsec-appsec-enabled-26
execution_time [-223.613ms; +235.789ms] or [-8.776%; +9.254%]scenario:appsec-appsec-enabled-with-attacks-24
execution_time [-152.493ms; +160.104ms] or [-4.932%; +5.178%]scenario:appsec-appsec-enabled-with-attacks-26
execution_time [-200848.057µs; +201936.623µs] or [-6.805%; +6.842%]scenario:appsec-control-20
execution_time [-124920.281µs; +124303.481µs] or [-7.569%; +7.532%]scenario:appsec-control-24
execution_time [-115064.437µs; +114672.070µs] or [-9.277%; +9.246%]scenario:appsec-control-26
execution_time [-135.984ms; +104.558ms] or [-11.179%; +8.596%]scenario:appsec-iast-no-vulnerability-control-20
execution_time [-14877.506µs; +16227.040µs] or [-5.720%; +6.239%]scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20
execution_time [-18.827ms; +9.704ms] or [-7.252%; +3.738%]scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20
execution_time [-14.265ms; +17.253ms] or [-5.589%; +6.759%]scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20
execution_time [-27.634ms; +33.271ms] or [-4.939%; +5.947%]scenario:debugger-line-probe-with-snapshot-default-26
cpu_user_time [-3146.837ms; +4742.805ms] or [-29.243%; +44.074%]execution_time [-3189.677ms; +4787.140ms] or [-27.728%; +41.615%]instructions [-27.6G instructions; +41.7G instructions] or [-30.569%; +46.147%]max_rss_usage [-9.136MB; +15.227MB] or [-5.591%; +9.318%]throughput [-967.274op/s; +662.865op/s] or [-32.652%; +22.376%]scenario:debugger-line-probe-with-snapshot-minimal-24
cpu_user_time [-3.114s; +0.089s] or [-32.311%; +0.919%]execution_time [-3.171s; +0.122s] or [-30.528%; +1.174%]instructions [-26.5G instructions; +0.6G instructions] or [-33.555%; +0.749%]throughput [-62.101op/s; +835.948op/s] or [-1.916%; +25.796%]scenario:debugger-line-probe-with-snapshot-minimal-26
cpu_user_time [-2.112s; +4.592s] or [-21.121%; +45.913%]execution_time [-2.067s; +4.569s] or [-19.266%; +42.575%]instructions [-18.8G instructions; +40.5G instructions] or [-22.487%; +48.383%]max_rss_usage [-6.350MB; +14.494MB] or [-3.934%; +8.980%]throughput [-991.500op/s; +442.249op/s] or [-31.887%; +14.223%]scenario:debugger-line-probe-without-snapshot-24
cpu_user_time [-1.932s; +4.058s] or [-22.050%; +46.306%]execution_time [-2.028s; +4.186s] or [-21.424%; +44.211%]instructions [-16.2G instructions; +34.7G instructions] or [-22.572%; +48.355%]max_rss_usage [-7.777MB; +17.312MB] or [-4.898%; +10.903%]throughput [-1148.609op/s; +571.098op/s] or [-32.476%; +16.147%]scenario:debugger-line-probe-without-snapshot-26
cpu_user_time [-3081.003ms; +4710.322ms] or [-28.709%; +43.891%]execution_time [-3090.594ms; +4714.283ms] or [-27.000%; +41.185%]instructions [-27.9G instructions; +41.7G instructions] or [-30.895%; +46.110%]max_rss_usage [-9.398MB; +14.482MB] or [-5.744%; +8.852%]throughput [-960.882op/s; +635.204op/s] or [-32.322%; +21.367%]scenario:dogstatsd-aggregated-26
cpu_usage_percentage [-7.945%; +4.150%]execution_time [-58.847ms; +116.926ms] or [-5.766%; +11.457%]throughput [-1274420.559op/s; +603139.507op/s] or [-8.545%; +4.044%]scenario:dogstatsd-with-tags-20
cpu_user_time [-430.358ms; +268.151ms] or [-8.547%; +5.325%]execution_time [-425.742ms; +269.954ms] or [-8.329%; +5.281%]throughput [-93712.597op/s; +145447.448op/s] or [-5.707%; +8.858%]scenario:plugin-claude-agent-sdk-compact-stream-scan-26
cpu_usage_percentage [-8.227%; +4.221%]cpu_user_time [-3506.652µs; +3898.652µs] or [-5.935%; +6.599%]scenario:plugin-graphql-long-with-depth-on-max-20
cpu_user_time [-692.669ms; +756.953ms] or [-5.396%; +5.897%]execution_time [-695.308ms; +766.273ms] or [-5.303%; +5.844%]throughput [-3.519op/s; +3.200op/s] or [-5.732%; +5.213%]scenario:test-optimization-large-suite-20
max_rss_usage [-3.120MB; +6.935MB] or [-3.925%; +8.725%]</details>
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 96.55%. Comparing base (
221c2fb) to head (b6c2dbe).:warning: Report is 8 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## master #9142 +/- ##
========================================
Coverage 96.54% 96.55%
========================================
Files 915 918 +3
Lines 121018 121394 +376
Branches 20840 20990 +150
========================================
+ Hits 116835 117207 +372
- Misses 4183 4187 +4
| Flag | Coverage Δ | |
|---|---|---|
| aiguard | 53.62% <100.00%> (-0.01%) | :arrow_down: |
| aiguard-integration | 57.05% <100.00%> (+0.03%) | :arrow_up: |
| apm-bucket-0 | 53.84% <100.00%> (-0.01%) | :arrow_down: |
| apm-bucket-1 | 58.15% <100.00%> (-0.01%) | :arrow_down: |
| apm-bucket-2 | 56.17% <100.00%> (+<0.01%) | :arrow_up: |
| apm-capabilities-tracing | 60.27% <53.15%> (-0.04%) | :arrow_down: |
| apm-integrations-aerospike | 53.01% <100.00%> (+<0.01%) | :arrow_up: |
| apm-integrations-confluentinc-kafka-javascript | 57.05% <100.00%> (-0.08%) | :arrow_down: |
| apm-integrations-couchbase | 53.32% <100.00%> (+<0.01%) | :arrow_up: |
| apm-integrations-http | 58.03% <100.00%> (-0.01%) | :arrow_down: |
| apm-integrations-kafkajs | 57.77% <100.00%> (+<0.01%) | :arrow_up: |
| apm-integrations-next | 54.30% <100.00%> (+<0.01%) | :arrow_up: |
| apm-integrations-prisma | 54.23% <100.00%> (-0.01%) | :arrow_down: |
| apm-integrations-tedious | 53.10% <100.00%> (+<0.01%) | :arrow_up: |
| appsec | 69.11% <100.00%> (-0.03%) | :arrow_down: |
| appsec-express_fastify_graphql | 65.67% <65.26%> (-0.08%) | :arrow_down: |
| appsec-integration | 45.60% <66.30%> (+0.09%) | :arrow_up: |
| appsec-kafka_ldapjs_lodash | 59.16% <100.00%> (-0.01%) | :arrow_down: |
| appsec-mongodb-core_mongoose_mysql | 62.32% <100.00%> (-0.02%) | :arrow_down: |
| appsec-next | 52.90% <100.00%> (-0.01%) | :arrow_down: |
| appsec-node-serialize_passport_postgres | 61.95% <100.00%> (-0.02%) | :arrow_down: |
| appsec-sourcing_stripe_template | 60.30% <100.00%> (-0.02%) | :arrow_down: |
| debugger | 65.74% <100.00%> (+0.01%) | :arrow_up: |
| instrumentations-bucket-0 | 48.80% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-1 | 55.02% <100.00%> (?) | |
| instrumentations-bucket-10 | 56.69% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-11 | 48.80% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-12 | 48.90% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-13 | 48.73% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-2 | 49.79% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-3 | 53.88% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-4 | 49.22% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-bucket-5 | 53.06% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-6 | 55.67% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-7 | 53.65% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-8 | 54.69% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-bucket-9 | 56.15% <100.00%> (-0.01%) | :arrow_down: |
| instrumentations-instrumentation-couchbase | 48.23% <100.00%> (+<0.01%) | :arrow_up: |
| instrumentations-integration-esbuild | 33.97% <100.00%> (+0.06%) | :arrow_up: |
| llmobs-ai_anthropic_bedrock | 57.79% <100.00%> (-0.01%) | :arrow_down: |
| llmobs-bucket-1 | 56.85% <100.00%> (-0.01%) | :arrow_down: |
| llmobs-openai | 57.62% <100.00%> (-0.01%) | :arrow_down: |
| llmobs-sdk | 60.03% <100.00%> (-0.01%) | :arrow_down: |
| llmobs-vertex-ai | 54.27% <100.00%> (-0.01%) | :arrow_down: |
| master-coverage | 96.55% <100.00%> (?) | |
| openfeature | 54.65% <100.00%> (+0.04%) | :arrow_up: |
| openfeature-unit | 49.88% <100.00%> (+<0.01%) | :arrow_up: |
| platform-core_esbuild_instrumentations-misc | 38.45% <100.00%> (+0.03%) | :arrow_up: |
| platform-integration | 62.22% <100.00%> (+0.02%) | :arrow_up: |
| platform-shimmer_unit-guardrails_webpack | 37.24% <100.00%> (+0.02%) | :arrow_up: |
| plugins-bucket-0 | 53.23% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-bucket-1 | 55.12% <100.00%> (+0.04%) | :arrow_up: |
| plugins-bucket-11 | 55.63% <100.00%> (-1.17%) | :arrow_down: |
| plugins-bucket-17 | ? | |
| plugins-bucket-18 | 57.12% <54.52%> (-0.53%) | :arrow_down: |
| plugins-bucket-19 | 55.44% <100.00%> (-1.75%) | :arrow_down: |
| plugins-bucket-20 | 57.51% <66.30%> (-1.93%) | :arrow_down: |
| plugins-bucket-4 | 53.90% <100.00%> (-0.01%) | :arrow_down: |
| plugins-bullmq_cassandra_cookie | 57.46% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-cookie-parser_crypto_dd-trace-api | 52.37% <100.00%> (-0.01%) | :arrow_down: |
| plugins-fetch_fs_generic-pool | 54.52% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-google-cloud-pubsub_grpc_handlebars | 59.93% <100.00%> (-0.01%) | :arrow_down: |
| plugins-hapi_hono_ioredis | 55.92% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-jest_knex_langgraph | 51.72% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-ldapjs_light-my-request_limitd-client | 53.47% <100.00%> (-0.03%) | :arrow_down: |
| plugins-lodash_mariadb_memcached | 54.27% <100.00%> (+<0.01%) | :arrow_up: |
| plugins-moleculer_mongodb_mongodb-core | 57.35% <100.00%> (?) | |
| plugins-mongodb_mongodb-core_mongoose | ? | |
| plugins-mongoose_multer_mysql | 54.77% <100.00%> (?) | |
| plugins-multer_mysql_mysql2 | ? | |
| plugins-mysql2_nats_node-serialize | 56.27% <100.00%> (?) | |
| plugins-nats_node-serialize_opensearch | ? | |
| plugins-opensearch_passport-http_pino | 55.12% <100.00%> (?) | |
| plugins-passport-http_pino_postgres | ? | |
| plugins-postgres_process_pug | 54.35% <100.00%> (?) | |
| plugins-process_pug_redis | ? | |
| plugins-redis_router_sequelize | 57.10% <100.00%> (?) | |
| plugins-test-and-upstream-rhea_undici_url | 57.08% <100.00%> (?) | |
| plugins-undici_url_valkey | ? | |
| plugins-valkey_vm_winston | 53.99% <100.00%> (?) | |
| plugins-vm_winston_ws | ? | |
| plugins-ws | 54.85% <100.00%> (?) | |
| profiling | 58.25% <100.00%> (-0.01%) | :arrow_down: |
| serverless-aws-sdk-aws-sdk | 50.71% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-bedrockruntime | 50.73% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-client | 52.01% <100.00%> (-0.01%) | :arrow_down: |
| serverless-aws-sdk-dynamodb | 51.86% <100.00%> (+0.06%) | :arrow_up: |
| serverless-aws-sdk-eventbridge | 46.27% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-kinesis | 54.76% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-lambda | 52.84% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-s3 | 51.58% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-serverless-peer-service | 54.78% <100.00%> (-0.01%) | :arrow_down: |
| serverless-aws-sdk-sns | 55.53% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-sqs | 55.96% <100.00%> (-0.06%) | :arrow_down: |
| serverless-aws-sdk-stepfunctions | 51.30% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-aws-sdk-util | 48.52% <100.00%> (+<0.01%) | :arrow_up: |
| serverless-bucket-0 | 55.28% <100.00%> (+0.04%) | :arrow_up: |
| serverless-bucket-1 | 56.07% <100.00%> (-0.01%) | :arrow_down: |
| test-optimization-cucumber | 73.00% <100.00%> (+0.02%) | :arrow_up: |
| test-optimization-cypress | 66.43% <100.00%> (+0.03%) | :arrow_up: |
| test-optimization-jest | 73.91% <100.00%> (-0.04%) | :arrow_down: |
| test-optimization-mocha | 74.33% <100.00%> (+0.05%) | :arrow_up: |
| test-optimization-playwright-playwright-atr | 61.63% <100.00%> (+0.04%) | :arrow_up: |
| test-optimization-playwright-playwright-efd | 61.83% <100.00%> (+0.04%) | :arrow_up: |
| test-optimization-playwright-playwright-final-status | 61.78% <100.00%> (+0.04%) | :arrow_up: |
| test-optimization-playwright-playwright-impacted-tests | 61.50% <100.00%> (+0.21%) | :arrow_up: |
| test-optimization-playwright-playwright-reporting | 61.41% <100.00%> (-0.15%) | :arrow_down: |
| test-optimization-playwright-playwright-test-management | 62.32% <100.00%> (-0.08%) | :arrow_down: |
| test-optimization-playwright-playwright-test-span | 61.55% <100.00%> (-0.01%) | :arrow_down: |
| test-optimization-selenium | 60.78% <100.00%> (-0.09%) | :arrow_down: |
| test-optimization-testopt | 59.19% <100.00%> (+0.12%) | :arrow_up: |
| test-optimization-vitest | 72.77% <100.00%> (+0.04%) | :arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
<sub><sub>!P1 Badge</sub></sub> Skip unsupported Mercurius versions in ESM tests
In the mercurius plugin job I checked .github/actions/plugins/test/action.yml, which runs yarn test:plugins:ci on oldest-maintenance-lts before the latest Node leg. The non-ESM spec already documents that Mercurius 15+ requires Node 20.9+ and skips those versions, but this ESM spec iterates the same withVersions matrix without that guard; with versions/package.json pinning Mercurius up to 16.9.0, the Node 18 CI leg will still sandbox/run the Fastify 5 variants and fail before reaching the latest-Node leg.
Useful? React with 👍 / 👎.
<sub><sub>!P2 Badge</sub></sub> Avoid caching raw sources without a request span
For existing graphql-js/Apollo/Yoga executions requestSpan is undefined, but this line still stores the raw query text as the key in the process-wide LRU on every parsed document. Only Mercurius request spans can ever consume this cache, so this bypasses the existing source config's privacy/perf gate and retains up to 500 query strings for all GraphQL users even when no graphql.request span exists; cache only when a Mercurius request span is present or use a non-raw key.
Useful? React with 👍 / 👎.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9e20ef6d1
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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".
</details>
<sub><sub>!P2 Badge</sub></sub> Cache all operations before Mercurius JIT skips execute
For a multi-operation document, this only caches the operation that happened to go through graphql.execute; if First runs cold and then Mercurius compiles/runs Second through its JIT path, execute never fires for Second, so getCachedRequestOperation(source, 'Second') stays empty and all warm Second request spans fall back to a bare operation name with no graphql.operation.type or signature. Cache metadata for every operation in the parsed document (or otherwise populate the selected operation before the JIT path) so JIT-only selections are labeled correctly.
Useful? React with 👍 / 👎.
<sub><sub>!P2 Badge</sub></sub> Backfill request metadata before validation failures
When Mercurius rejects after parsing/validation but before graphql.execute runs, such as an unknown field or GET mutation, this execute-only backfill never happens. Named queries that are sent without a separate operationName argument then finish their graphql.request error span with an empty resource and no graphql.operation.type/name tags even though the parsed document was available during validation, which makes these error traces hard to group.
Useful? React with 👍 / 👎.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecc38dc2d2
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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".
</details>
blocking: pre-parsed DocumentNode requests lose their operation metadata on the Mercurius JIT warm path.
request.js turns non-string sources into docSource = undefined, and utils.js returns before caching when docSource === undefined. That means the cold parsed-AST call can be refined by validate, but the second call can hit Mercurius's JIT path where graphql.execute does not fire. The graphql.request span then has no cached operation metadata to recover.
Verified with:
unset OTEL_TRACES_EXPORTER OTEL_LOGS_EXPORTER OTEL_METRICS_EXPORTER
NODE_PATH=/Users/crystal.magloire/Node_Tracer/dd-trace-js/node_modules RANGE=16 \
/Users/crystal.magloire/Node_Tracer/dd-trace-js/node_modules/.bin/mocha \
packages/datadog-plugin-mercurius/test/index.spec.js \
--grep "carries the operation signature for a pre-parsed document on the JIT warm path"
The focused test shape I used warms the same parsed document once, then asserts the second call:
it('carries the operation signature for a pre-parsed document on the JIT warm path', async () => {
const query = 'query ParsedAstWarm { hello }'
const document = require('../../../versions/graphql').get().parse(query)
const warmup = agent.assertSomeTraces(traces => {
const execute = traces[0].find(span => span.name === 'graphql.execute')
assert.ok(execute)
}, { spanResourceMatch: /ParsedAstWarm/ })
await Promise.all([warmup, app.graphql(document)])
const assertion = agent.assertSomeTraces(traces => {
const request = traces[0].find(span => span.name === expectedSchema.server.opName)
const execute = traces[0].find(span => span.name === 'graphql.execute')
assert.ok(request)
assert.strictEqual(execute, undefined)
assertObjectContains(request, {
meta: {
'graphql.operation.type': 'query',
'graphql.operation.name': 'ParsedAstWarm'
}
})
assert.match(request.resource, /ParsedAstWarm/)
})
return Promise.all([assertion, app.graphql(document)])
})
Failure result: the warm request span is resource: "graphql.request" and does not include graphql.operation.name or graphql.operation.type. We should either cache parsed-AST metadata for the warm path too, or make the request boundary able to recover it some other way, and keep a focused regression test for this case.
Approved these changes.
bengl
BridgeAR
Summary
Mercurius funnels every operation through one async function and parses,
validates, and executes internally, so a query served from its JIT-compiled
path runs no
graphql.executeand produced no span at all. A top-levelgraphql.requestspan now opens at that funnel (fastifyGraphQl) viaorchestrion, parents the parse/validate/execute sub-spans, and carries the
request text plus operation name/type. It survives the JIT warm path, where no
execute span fires.
1. The request boundary only sees the raw source and operationName; the execute
sub-plugin backfills the precise operation signature onto the request span
once the document is parsed, so the hot path never re-parses.
2. v0 keeps the cross-tracer
graphql.requestname; v1 usesgraphql.server.request. The v1 overlap with the execute span's name is aknown cross-tracer wart left for a separate breaking change.
3. The funnel yields one request span per operation, so a batched request
produces one span per operation rather than one per HTTP request.
Test plan
New
mercuriusCI job runs the plugin spec across majors 13-16 (15+ gated toNode 20+). Coverage: request-span source/operation tags, execute parented under
request with a shared resource, resolver and pre-execute validation errors,
anonymous and programmatic
app.graphql()calls, the JIT warm path, batchedqueries, and
sourceon/off.Fixes: https://github.com/DataDog/dd-trace-js/issues/1141