Skip to content

fix(profiling): stale ProfilingContext cache causing missing trace endpoint labels#7786

Merged
BridgeAR merged 2 commits intomasterfrom
szegedi/fix-endpoint-label-acf
Mar 17, 2026
Merged

fix(profiling): stale ProfilingContext cache causing missing trace endpoint labels#7786
BridgeAR merged 2 commits intomasterfrom
szegedi/fix-endpoint-label-acf

Conversation

@szegedi
Copy link
Copy Markdown
Contributor

@szegedi szegedi commented Mar 16, 2026

I noticed that we don't seem to be getting tracing endpoints associated with profiling samples with ACF anymore. Turns out that:

  • TracingPlugin.startSpan() calls storage.enterWith({span}) immediately on span creation, before the plugin calls addRequestTags() to set span.type='web'. This means the first enterCh event fires with span.type unset.
  • #getProfilingContext() was caching webTags=undefined from that first activation, so the subsequent activation (with span.type='web' already set) incorrectly served the stale cache and never produced trace endpoint labels in CPU profiles.

We fix it by skipping writing to the span[ProfilingContext] cache when endpoint collection is enabled, webTags is undefined, and span.type is not yet set. This forces recomputation on the next activation, by which time span.type='web' will be set. The fix applies to both the ACF path (Node.js 24 CPED) and the non-ACF path (legacy async_hooks), even though async_hooks is not really susceptible to it as it invokes the #enter very often.

We still miss the endpoints when setRequestTags is called in the same activation, fortunately web.instrument() provides a subsequent second activation as well. It'd be possible to fix this more thoroughly by adding a DC for observing setRequestTags, but I'd like to save that for after some other soon-incoming-changes. This fix reenables endpoint tracing for virtually all cases already.

Test plan

  • New unit tests in wall.spec.js cover ACF path, non-ACF path, and child span inheritance
  • Run existing wall profiler tests: cd packages/dd-trace && yarn test test/profiling/profilers/wall.spec.js
  • Verify trace endpoint labels appear in profiles collected against a real Express app with DD_PROFILING_ENDPOINT_COLLECTION_ENABLED=true

Here's a screenshot profiling a test application after the fix:
Screenshot 2026-03-16 at 13 54 49

Compare to screenshot before the fix with no "For Endpoints" section:
Screenshot 2026-03-16 at 13 56 43

🤖 Generated with Claude Code

…point labels

TracingPlugin.startSpan() calls storage.enterWith({span}) immediately on span
creation, before the plugin calls addRequestTags() to set span.type='web'. The
first enterCh event therefore fires with span.type unset, causing
#getProfilingContext to compute webTags=undefined and cache that result on the
span. When the span is re-activated moments later (with span.type='web' already
set) the stale cache is returned and webTags stays undefined for the entire
request, so no trace endpoint labels appear in the CPU profile.

Fix: skip writing the cache when endpointCollectionEnabled is true, webTags is
undefined, *and* the span's type is not yet set. On the next activation the
context is recomputed; once span.type='web' is known webTags is found and the
result is cached normally.

This affects both the ACF path (pprof.time.setContext per activation) and the
non-ACF path (_currentContext.ref mutation), so the fix lives in
#getProfilingContext which is shared by both.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.55%. Comparing base (10b22f9) to head (ed5c375).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7786      +/-   ##
==========================================
+ Coverage   80.34%   80.55%   +0.21%     
==========================================
  Files         743      743              
  Lines       32296    32297       +1     
==========================================
+ Hits        25947    26017      +70     
+ Misses       6349     6280      -69     
Flag Coverage Δ
aiguard-macos 39.06% <ø> (-0.10%) ⬇️
aiguard-ubuntu 39.18% <ø> (-0.10%) ⬇️
aiguard-windows 38.91% <ø> (-0.10%) ⬇️
apm-capabilities-tracing-macos 48.93% <0.00%> (-0.01%) ⬇️
apm-capabilities-tracing-ubuntu 48.97% <0.00%> (-0.01%) ⬇️
apm-capabilities-tracing-windows 48.71% <0.00%> (+0.04%) ⬆️
apm-integrations-child-process 38.37% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 37.14% <ø> (-0.24%) ⬇️
apm-integrations-couchbase-eol 37.75% <ø> (+0.04%) ⬆️
apm-integrations-oracledb 37.59% <ø> (-0.10%) ⬇️
appsec-express 55.16% <ø> (-0.07%) ⬇️
appsec-fastify 51.51% <ø> (-0.07%) ⬇️
appsec-graphql 51.72% <ø> (-0.06%) ⬇️
appsec-kafka 44.24% <ø> (-0.08%) ⬇️
appsec-ldapjs 43.90% <ø> (-0.08%) ⬇️
appsec-lodash 43.56% <ø> (-0.08%) ⬇️
appsec-macos 58.17% <ø> (-0.07%) ⬇️
appsec-mongodb-core 48.68% <ø> (-0.08%) ⬇️
appsec-mongoose 49.33% <ø> (-0.08%) ⬇️
appsec-mysql 50.78% <ø> (-0.07%) ⬇️
appsec-node-serialize 43.08% <ø> (-0.08%) ⬇️
appsec-passport 47.52% <ø> (-0.09%) ⬇️
appsec-postgres 50.50% <ø> (-0.07%) ⬇️
appsec-sourcing 42.49% <ø> (-0.08%) ⬇️
appsec-template 43.25% <ø> (-0.08%) ⬇️
appsec-ubuntu 58.24% <ø> (-0.07%) ⬇️
appsec-windows 58.03% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 32.24% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.39% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 37.68% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.22% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.54% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.35% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 40.02% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs 31.86% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 29.64% <ø> (ø)
instrumentations-instrumentation-http 39.66% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.24% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.37% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.14% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.14% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport 43.95% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.61% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.15% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.58% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.17% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 32.18% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.22% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.14% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-when 32.19% <ø> (-0.10%) ⬇️
llmobs-ai 42.13% <ø> (-0.09%) ⬇️
llmobs-anthropic 40.16% <ø> (-0.09%) ⬇️
llmobs-bedrock 39.11% <ø> (-0.08%) ⬇️
llmobs-google-genai 39.66% <ø> (-0.09%) ⬇️
llmobs-langchain 39.89% <ø> (-0.08%) ⬇️
llmobs-openai 43.84% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 39.91% <ø> (-0.09%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 48.35% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
plugins-azure-durable-functions 25.62% <ø> (ø)
plugins-azure-event-hubs 25.79% <ø> (ø)
plugins-azure-service-bus 25.15% <ø> (ø)
plugins-bullmq 44.15% <ø> (+<0.01%) ⬆️
plugins-cassandra 37.63% <ø> (-0.23%) ⬇️
plugins-cookie 26.84% <ø> (ø)
plugins-cookie-parser 26.63% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.20% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.78% <ø> (ø)
plugins-express-session 26.59% <ø> (ø)
plugins-fastify 42.10% <ø> (-0.09%) ⬇️
plugins-fetch 38.19% <ø> (-0.09%) ⬇️
plugins-fs 38.47% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.83% <ø> (ø)
plugins-google-cloud-pubsub 45.31% <ø> (-0.09%) ⬇️
plugins-grpc 40.78% <ø> (-0.09%) ⬇️
plugins-handlebars 26.82% <ø> (ø)
plugins-hapi 40.02% <ø> (-0.10%) ⬇️
plugins-hono 40.28% <ø> (-0.10%) ⬇️
plugins-ioredis 38.28% <ø> (-0.10%) ⬇️
plugins-knex 26.46% <ø> (ø)
plugins-ldapjs 24.32% <ø> (ø)
plugins-light-my-request 26.19% <ø> (ø)
plugins-limitd-client 32.52% <ø> (-0.10%) ⬇️
plugins-lodash 25.92% <ø> (ø)
plugins-mariadb 39.32% <ø> (-0.10%) ⬇️
plugins-memcached 38.00% <ø> (-0.10%) ⬇️
plugins-microgateway-core 39.08% <ø> (-0.10%) ⬇️
plugins-moleculer 40.37% <ø> (-0.09%) ⬇️
plugins-mongodb 39.02% <ø> (-0.10%) ⬇️
plugins-mongodb-core 38.85% <ø> (-0.10%) ⬇️
plugins-mongoose 38.71% <ø> (-0.10%) ⬇️
plugins-multer 26.59% <ø> (ø)
plugins-mysql 39.01% <ø> (-0.10%) ⬇️
plugins-mysql2 39.11% <ø> (-0.10%) ⬇️
plugins-node-serialize 26.89% <ø> (ø)
plugins-opensearch 37.46% <ø> (-0.10%) ⬇️
plugins-passport-http 26.64% <ø> (ø)
plugins-postgres 35.49% <ø> (-0.09%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.84% <ø> (ø)
plugins-redis 38.74% <ø> (-0.10%) ⬇️
plugins-router 42.83% <ø> (-0.10%) ⬇️
plugins-sequelize 25.43% <ø> (ø)
plugins-test-and-upstream-amqp10 38.35% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-amqplib 43.73% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 38.98% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.53% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.78% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.68% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 39.97% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.27% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 38.75% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 43.91% <ø> (-0.10%) ⬇️
plugins-undici 38.97% <ø> (-0.09%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 37.94% <ø> (-0.10%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 33.97% <ø> (-0.10%) ⬇️
plugins-ws 41.73% <ø> (-0.10%) ⬇️
profiling-macos 40.47% <100.00%> (+0.60%) ⬆️
profiling-ubuntu 40.60% <100.00%> (+0.60%) ⬆️
profiling-windows 42.15% <100.00%> (+0.97%) ⬆️
serverless-azure-functions-client 25.50% <ø> (ø)
serverless-azure-functions-eventhubs 25.50% <ø> (ø)
serverless-azure-functions-servicebus 25.50% <ø> (ø)

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

Overall package size

Self size: 4.98 MB
Deduped: 5.82 MB
No deduping: 5.82 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 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 Mar 16, 2026

Benchmarks

Benchmark execution time: 2026-03-16 13:09:24

Comparing candidate commit ed5c375 in PR branch szegedi/fix-endpoint-label-acf with baseline commit 10b22f9 in branch master.

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

@szegedi szegedi changed the title profiling: fix stale ProfilingContext cache causing missing trace endpoint labels fix(profiling): stale ProfilingContext cache causing missing trace endpoint labels Mar 16, 2026
@szegedi szegedi marked this pull request as ready for review March 16, 2026 13:18
@szegedi szegedi requested a review from a team as a code owner March 16, 2026 13:18
@BridgeAR BridgeAR merged commit f3c5706 into master Mar 17, 2026
790 checks passed
@BridgeAR BridgeAR deleted the szegedi/fix-endpoint-label-acf branch March 17, 2026 13:52
dd-octo-sts bot pushed a commit that referenced this pull request Mar 17, 2026
…dpoint labels (#7786)

TracingPlugin.startSpan() calls storage.enterWith({span}) immediately on span
creation, before the plugin calls addRequestTags() to set span.type='web'. The
first enterCh event therefore fires with span.type unset, causing
#getProfilingContext to compute webTags=undefined and cache that result on the
span. When the span is re-activated moments later (with span.type='web' already
set) the stale cache is returned and webTags stays undefined for the entire
request, so no trace endpoint labels appear in the CPU profile.

Fix: skip writing the cache when endpointCollectionEnabled is true, webTags is
undefined, *and* the span's type is not yet set. On the next activation the
context is recomputed; once span.type='web' is known webTags is found and the
result is cached normally.

This affects both the ACF path (pprof.time.setContext per activation) and the
non-ACF path (_currentContext.ref mutation), so the fix lives in
#getProfilingContext which is shared by both.

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
@dd-octo-sts dd-octo-sts bot mentioned this pull request Mar 17, 2026
juan-fernandez pushed a commit that referenced this pull request Mar 18, 2026
…dpoint labels (#7786)

TracingPlugin.startSpan() calls storage.enterWith({span}) immediately on span
creation, before the plugin calls addRequestTags() to set span.type='web'. The
first enterCh event therefore fires with span.type unset, causing
#getProfilingContext to compute webTags=undefined and cache that result on the
span. When the span is re-activated moments later (with span.type='web' already
set) the stale cache is returned and webTags stays undefined for the entire
request, so no trace endpoint labels appear in the CPU profile.

Fix: skip writing the cache when endpointCollectionEnabled is true, webTags is
undefined, *and* the span's type is not yet set. On the next activation the
context is recomputed; once span.type='web' is known webTags is found and the
result is cached normally.

This affects both the ACF path (pprof.time.setContext per activation) and the
non-ACF path (_currentContext.ref mutation), so the fix lives in
#getProfilingContext which is shared by both.

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.

3 participants