Skip to content

fix: reduce ACF overhead in storage and noop contexts#7465

Merged
BridgeAR merged 6 commits intomasterfrom
BridgeAR/2026-02-09-reduce-acf-triggers
Feb 10, 2026
Merged

fix: reduce ACF overhead in storage and noop contexts#7465
BridgeAR merged 6 commits intomasterfrom
BridgeAR/2026-02-09-reduce-acf-triggers

Conversation

@BridgeAR
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR commented Feb 9, 2026

Replace manual enterWith/restore patterns with run() across all noop context wrappers (log writer, exporters, git utils). This halves AsyncContextFrame transitions on Node.js 22+: run() restores via AsyncContextFrame.set() (no extra frame), while enterWith/restore created a second frame that triggered the profiler's setContext() again.

In DatadogStorage, feature-detect whether ALS.run() delegates to enterWith() (ACF behavior) and only fall back to the manual approach on older runtimes without AsyncContextFrame.

Replace manual enterWith/restore patterns with run() across
all noop context wrappers (log writer, exporters, git utils).
This halves AsyncContextFrame transitions on Node.js 22+:
run() restores via AsyncContextFrame.set() (no extra frame),
while enterWith/restore created a second frame that triggered
the profiler's setContext() again.

In DatadogStorage, feature-detect whether ALS.run() delegates
to enterWith() (ACF behavior) and only fall back to the manual
approach on older runtimes without AsyncContextFrame.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 9, 2026

Overall package size

Self size: 4.58 MB
Deduped: 5.42 MB
No deduping: 5.42 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 813.08 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@datadog-datadog-prod-us1

This comment has been minimized.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Feb 9, 2026

Benchmarks

Benchmark execution time: 2026-02-10 17:06:13

Comparing candidate commit b04c8bd in PR branch BridgeAR/2026-02-09-reduce-acf-triggers with baseline commit 5fd961c in branch master.

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

@BridgeAR BridgeAR marked this pull request as ready for review February 9, 2026 15:55
@BridgeAR BridgeAR requested review from a team as code owners February 9, 2026 15:55
Comment thread packages/datadog-core/src/storage.js Outdated
Comment thread packages/datadog-core/src/storage.js Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 98.59155% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.31%. Comparing base (5fd961c) to head (b04c8bd).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
packages/dd-trace/src/exporters/common/request.js 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7465      +/-   ##
==========================================
- Coverage   80.34%   80.31%   -0.04%     
==========================================
  Files         731      731              
  Lines       31093    31133      +40     
==========================================
+ Hits        24982    25004      +22     
- Misses       6111     6129      +18     
Flag Coverage Δ
aiguard-macos 39.06% <69.44%> (-0.12%) ⬇️
aiguard-ubuntu 39.18% <83.33%> (-0.04%) ⬇️
aiguard-windows 38.92% <72.22%> (-0.15%) ⬇️
apm-capabilities-tracing-macos 48.77% <64.78%> (-0.08%) ⬇️
apm-capabilities-tracing-ubuntu 48.85% <71.83%> (+<0.01%) ⬆️
apm-capabilities-tracing-windows 48.33% <64.78%> (-0.25%) ⬇️
apm-integrations-child-process 38.64% <83.33%> (-0.04%) ⬇️
apm-integrations-couchbase-18 37.54% <77.77%> (+0.11%) ⬆️
apm-integrations-couchbase-eol 38.03% <77.77%> (+0.11%) ⬆️
apm-integrations-oracledb 38.04% <83.33%> (-0.06%) ⬇️
appsec-express 55.44% <83.33%> (+<0.01%) ⬆️
appsec-fastify 52.02% <83.33%> (-0.04%) ⬇️
appsec-graphql 52.40% <77.77%> (+0.01%) ⬆️
appsec-kafka 44.63% <83.33%> (-0.09%) ⬇️
appsec-ldapjs 44.38% <77.77%> (-0.01%) ⬇️
appsec-lodash 44.06% <77.77%> (-0.01%) ⬇️
appsec-macos 58.51% <49.01%> (-0.04%) ⬇️
appsec-mongodb-core 49.17% <77.77%> (-0.10%) ⬇️
appsec-mongoose 49.97% <77.77%> (+0.01%) ⬆️
appsec-mysql 51.35% <83.33%> (+0.01%) ⬆️
appsec-node-serialize 43.58% <77.77%> (-0.01%) ⬇️
appsec-passport 48.15% <77.77%> (-0.05%) ⬇️
appsec-postgres 51.14% <83.33%> (+0.01%) ⬆️
appsec-sourcing 42.92% <77.77%> (-0.01%) ⬇️
appsec-template 43.75% <77.77%> (-0.01%) ⬇️
appsec-ubuntu 58.59% <58.82%> (+0.01%) ⬆️
appsec-windows 58.37% <56.86%> (-0.06%) ⬇️
instrumentations-instrumentation-bluebird 32.32% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-body-parser 40.85% <77.77%> (+0.02%) ⬆️
instrumentations-instrumentation-child_process 37.95% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-cookie-parser 34.55% <77.77%> (-0.06%) ⬇️
instrumentations-instrumentation-express 34.89% <77.77%> (-0.06%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.68% <77.77%> (-0.06%) ⬇️
instrumentations-instrumentation-express-session 40.47% <77.77%> (-0.05%) ⬇️
instrumentations-instrumentation-fs 31.92% <83.33%> (-0.03%) ⬇️
instrumentations-instrumentation-generic-pool 30.20% <27.45%> (+0.39%) ⬆️
instrumentations-instrumentation-http 39.66% <77.77%> (-0.07%) ⬇️
instrumentations-instrumentation-knex 32.32% <77.77%> (-0.03%) ⬇️
instrumentations-instrumentation-mongoose 33.66% <77.77%> (-0.06%) ⬇️
instrumentations-instrumentation-multer 40.59% <77.77%> (+0.02%) ⬆️
instrumentations-instrumentation-mysql2 38.33% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-passport 44.45% <77.77%> (+3.58%) ⬆️
instrumentations-instrumentation-passport-http 44.10% <77.77%> (+3.26%) ⬆️
instrumentations-instrumentation-passport-local 44.66% <77.77%> (+3.82%) ⬆️
instrumentations-instrumentation-pg 37.85% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-promise 32.25% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-promise-js 32.26% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-q 32.30% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-url 32.22% <77.77%> (-0.04%) ⬇️
instrumentations-instrumentation-when 32.27% <77.77%> (-0.04%) ⬇️
llmobs-ai 41.47% <83.33%> (-0.04%) ⬇️
llmobs-anthropic 40.66% <83.33%> (-0.06%) ⬇️
llmobs-bedrock 39.54% <77.77%> (-0.06%) ⬇️
llmobs-google-genai 40.15% <83.33%> (-0.06%) ⬇️
llmobs-langchain 39.69% <83.33%> (-0.05%) ⬇️
llmobs-openai 44.51% <83.33%> (-0.07%) ⬇️
llmobs-vertex-ai 40.44% <83.33%> (-0.06%) ⬇️
platform-core 29.71% <85.71%> (+1.62%) ⬆️
platform-esbuild 32.89% <85.71%> (+1.40%) ⬆️
platform-instrumentations-misc 40.53% <80.00%> (+0.91%) ⬆️
platform-shimmer 36.14% <85.71%> (+1.31%) ⬆️
platform-unit-guardrails 31.27% <64.28%> (+0.89%) ⬆️
plugins-azure-event-hubs 24.02% <85.71%> (+1.38%) ⬆️
plugins-azure-service-bus 23.42% <85.71%> (+1.34%) ⬆️
plugins-bullmq 43.78% <83.33%> (+0.04%) ⬆️
plugins-cassandra 38.08% <83.33%> (-0.06%) ⬇️
plugins-cookie 25.08% <85.71%> (+1.38%) ⬆️
plugins-cookie-parser 24.87% <85.71%> (+1.37%) ⬆️
plugins-crypto 24.72% <85.71%> (+1.83%) ⬆️
plugins-dd-trace-api 38.49% <77.77%> (-0.04%) ⬇️
plugins-express-mongo-sanitize 25.04% <85.71%> (+1.36%) ⬆️
plugins-express-session 24.83% <85.71%> (+1.37%) ⬆️
plugins-fastify 42.58% <83.33%> (-0.05%) ⬇️
plugins-fetch 38.64% <83.33%> (-0.06%) ⬇️
plugins-fs 38.74% <83.33%> (-0.04%) ⬇️
plugins-generic-pool 24.06% <85.71%> (+1.38%) ⬆️
plugins-google-cloud-pubsub 45.80% <83.33%> (-0.02%) ⬇️
plugins-grpc 41.33% <83.33%> (-0.07%) ⬇️
plugins-handlebars 25.08% <85.71%> (+1.36%) ⬆️
plugins-hapi 40.49% <83.33%> (-0.05%) ⬇️
plugins-hono 40.75% <83.33%> (+0.02%) ⬆️
plugins-ioredis 38.54% <83.33%> (-0.04%) ⬇️
plugins-knex 24.80% <85.71%> (+1.29%) ⬆️
plugins-ldapjs 22.61% <85.71%> (+1.33%) ⬆️
plugins-light-my-request 24.48% <85.71%> (+1.33%) ⬆️
plugins-limitd-client 32.62% <83.33%> (-0.04%) ⬇️
plugins-lodash 24.13% <85.71%> (+1.39%) ⬆️
plugins-mariadb 39.67% <83.33%> (-0.04%) ⬇️
plugins-memcached 38.27% <83.33%> (-0.04%) ⬇️
plugins-microgateway-core 39.50% <77.77%> (-0.04%) ⬇️
plugins-moleculer 40.88% <83.33%> (-0.07%) ⬇️
plugins-mongodb 39.59% <83.33%> (-0.07%) ⬇️
plugins-mongodb-core 39.19% <83.33%> (-0.04%) ⬇️
plugins-mongoose 39.22% <83.33%> (-0.06%) ⬇️
plugins-multer 24.83% <85.71%> (+1.37%) ⬆️
plugins-mysql 39.30% <83.33%> (-0.04%) ⬇️
plugins-mysql2 39.37% <83.33%> (-0.04%) ⬇️
plugins-node-serialize 25.12% <85.71%> (+1.38%) ⬆️
plugins-opensearch 37.91% <83.33%> (-0.06%) ⬇️
plugins-passport-http 24.91% <85.71%> (+1.35%) ⬆️
plugins-postgres 35.83% <58.82%> (+0.02%) ⬆️
plugins-process 24.72% <85.71%> (+1.83%) ⬆️
plugins-pug 25.08% <85.71%> (+1.38%) ⬆️
plugins-redis 39.02% <83.33%> (-0.04%) ⬇️
plugins-router 43.36% <83.33%> (+0.02%) ⬆️
plugins-sequelize 23.66% <85.71%> (+1.38%) ⬆️
plugins-test-and-upstream-amqp10 38.61% <83.33%> (-0.04%) ⬇️
plugins-test-and-upstream-amqplib 43.96% <83.33%> (-0.05%) ⬇️
plugins-test-and-upstream-apollo 39.33% <77.77%> (-0.08%) ⬇️
plugins-test-and-upstream-avsc 38.88% <83.33%> (-0.04%) ⬇️
plugins-test-and-upstream-bunyan 33.93% <83.33%> (-0.04%) ⬇️
plugins-test-and-upstream-connect 41.17% <83.33%> (+0.02%) ⬆️
plugins-test-and-upstream-graphql 40.29% <83.33%> (-0.04%) ⬇️
plugins-test-and-upstream-koa 40.75% <83.33%> (+0.02%) ⬆️
plugins-test-and-upstream-protobufjs 39.11% <83.33%> (-0.04%) ⬇️
plugins-test-and-upstream-rhea 44.25% <83.33%> (-0.01%) ⬇️
plugins-undici 39.43% <83.33%> (-0.06%) ⬇️
plugins-url 24.72% <85.71%> (+1.83%) ⬆️
plugins-valkey 38.19% <83.33%> (-0.01%) ⬇️
plugins-vm 24.72% <85.71%> (+1.83%) ⬆️
plugins-winston 34.31% <83.33%> (-0.06%) ⬇️
plugins-ws 42.24% <83.33%> (-0.07%) ⬇️
profiling-macos 40.04% <79.62%> (-0.13%) ⬇️
profiling-ubuntu 40.17% <88.88%> (-0.05%) ⬇️
profiling-windows 41.42% <82.14%> (-0.15%) ⬇️
serverless-azure-functions-client 23.75% <85.71%> (+1.37%) ⬆️
serverless-azure-functions-eventhubs 23.75% <85.71%> (+1.37%) ⬆️
serverless-azure-functions-servicebus 23.75% <85.71%> (+1.37%) ⬆️

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.

@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
@DataDog DataDog deleted a comment from codecov Bot Feb 9, 2026
szegedi
szegedi previously approved these changes Feb 10, 2026
Comment thread packages/dd-trace/test/appsec/iast/analyzers/path-traversal-analyzer.spec.js Outdated
rochdev
rochdev previously approved these changes Feb 10, 2026
Copy link
Copy Markdown
Member

@rochdev rochdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Added a few comments but mostly just as notes.

}

const hasExecArg = (arg) => process.execArgv.includes(arg) || String(NODE_OPTIONS).includes(arg)
const canUseAsyncContextFrame = samplingContextsAvailable && isACFActive
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of exposing isACFActive as that should be a hidden implementation detail, but it seems better than the current alternative.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly my thoughts :D

als.run(1, () => {})
als.disable()
return active
})()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this right at file load time can have side-effects, but I think that's fine because if this file is loaded then the rest of the library is probably loaded as well at which point we'll end up getting those side-effects anyway.

@CarlesDD CarlesDD dismissed stale reviews from rochdev and szegedi via b04c8bd February 10, 2026 16:53
Copy link
Copy Markdown
Contributor

@CarlesDD CarlesDD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from Appsec

@BridgeAR BridgeAR merged commit a3dff51 into master Feb 10, 2026
791 checks passed
@BridgeAR BridgeAR deleted the BridgeAR/2026-02-09-reduce-acf-triggers branch February 10, 2026 17:55
dd-octo-sts Bot pushed a commit that referenced this pull request Feb 10, 2026
* fix: reduce ACF overhead in storage and noop contexts

Replace manual enterWith/restore patterns with run() across
all noop context wrappers (log writer, exporters, git utils).
This halves AsyncContextFrame transitions on Node.js 22+:
run() restores via AsyncContextFrame.set() (no extra frame),
while enterWith/restore created a second frame that triggered
the profiler's setContext() again.

In DatadogStorage, feature-detect whether ALS.run() delegates
to enterWith() (ACF behavior) and only fall back to the manual
approach on older runtimes without AsyncContextFrame.

* doc: remove todo by explaining the behavior

* fix: exclude node:internals ALS from path line detection (#7475)
juan-fernandez pushed a commit that referenced this pull request Feb 12, 2026
* fix: reduce ACF overhead in storage and noop contexts

Replace manual enterWith/restore patterns with run() across
all noop context wrappers (log writer, exporters, git utils).
This halves AsyncContextFrame transitions on Node.js 22+:
run() restores via AsyncContextFrame.set() (no extra frame),
while enterWith/restore created a second frame that triggered
the profiler's setContext() again.

In DatadogStorage, feature-detect whether ALS.run() delegates
to enterWith() (ACF behavior) and only fall back to the manual
approach on older runtimes without AsyncContextFrame.

* doc: remove todo by explaining the behavior

* fix: exclude node:internals ALS from path line detection (#7475)
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.

5 participants