Skip to content

feat(debugger): implement capture expressions#7431

Merged
watson merged 2 commits intomasterfrom
watson/DEBUG-5011/capture-expressions
Feb 13, 2026
Merged

feat(debugger): implement capture expressions#7431
watson merged 2 commits intomasterfrom
watson/DEBUG-5011/capture-expressions

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Feb 4, 2026

What does this PR do?

This PR implements capture expressions for Live Debugger/Dynamic Instrumentation log probes, providing an alternative to full snapshot capture. Instead of serializing entire object graphs, users can now define specific expressions to capture, giving them precise control over what data gets collected and addressing the 1MB Event Platform payload limit.

Motivation

Log probes currently face a significant limitation: when captureSnapshot: true is enabled, the debugger serializes entire object graphs. Even with depth restrictions in place, this approach might hit the 1MB Event Platform limit. The problem becomes frustrating when users need a specific piece of deeply nested data, increasing the capture depth to reach that value inadvertently captures large amounts of uninteresting data from other parts of the object graph.

Capture expressions solve this by letting users define exactly which data they need. When captureExpressions is defined on a probe, the debugger switches to expression-only mode, evaluating and serializing only the specified expressions. Each expression can optionally override the default capture limits for depth, collection size, field count, and string length, providing fine-grained control over what gets captured.

The implementation includes robust error handling that distinguishes between two types of failures. Evaluation errors, like ReferenceError for undefined variables, are expected JavaScript errors that get reported per-expression while allowing other expressions to continue. Fatal errors, such as protocol failures, indicate something more serious has gone wrong, so the entire capture expressions feature is disabled for that probe until the probe is re-applied, preventing repeated failures on every breakpoint hit.

Time budget enforcement remains a critical aspect of the debugger's performance profile: When capture expressions are being evaluated, the timeout applies across all expressions. If the time budget is exceeded, successfully evaluated expressions are included in the snapshot, while remaining unevaluated expressions appear with a notCapturedReason field indicating the timeout was reached. This ensures the snapshot structure remains predictable even when operating under time pressure.

Additional Notes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2026

Overall package size

Self size: 4.61 MB
Deduped: 5.45 MB
No deduping: 5.45 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

@watson watson self-assigned this Feb 4, 2026
@watson watson added semver-minor debugger Dynamic Instrumentation & Live Debugger labels Feb 4, 2026
Copy link
Copy Markdown
Collaborator Author

watson commented Feb 4, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Feb 4, 2026

Benchmarks

Benchmark execution time: 2026-02-13 12:48:48

Comparing candidate commit 819f73e in PR branch watson/DEBUG-5011/capture-expressions with baseline commit 0312991 in branch master.

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

@watson watson force-pushed the watson/DEBUG-5011/capture-expressions branch from ea82eb7 to 90ae293 Compare February 4, 2026 10:00
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.22%. Comparing base (0312991) to head (819f73e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7431      +/-   ##
==========================================
- Coverage   80.23%   80.22%   -0.01%     
==========================================
  Files         731      731              
  Lines       31194    31194              
==========================================
- Hits        25027    25025       -2     
- Misses       6167     6169       +2     
Flag Coverage Δ
aiguard-macos 39.07% <ø> (-0.11%) ⬇️
aiguard-ubuntu 39.19% <ø> (-0.11%) ⬇️
aiguard-windows 38.93% <ø> (-0.11%) ⬇️
apm-capabilities-tracing-macos 48.80% <ø> (ø)
apm-capabilities-tracing-ubuntu 48.83% <ø> (ø)
apm-capabilities-tracing-windows 48.52% <ø> (ø)
apm-integrations-child-process 38.64% <ø> (-0.11%) ⬇️
apm-integrations-couchbase-18 37.53% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-eol 37.87% <ø> (-0.10%) ⬇️
apm-integrations-oracledb 38.06% <ø> (-0.10%) ⬇️
appsec-express 55.44% <ø> (-0.08%) ⬇️
appsec-fastify 52.05% <ø> (-0.08%) ⬇️
appsec-graphql 52.40% <ø> (-0.07%) ⬇️
appsec-kafka 44.69% <ø> (-0.03%) ⬇️
appsec-ldapjs 44.39% <ø> (-0.09%) ⬇️
appsec-lodash 44.07% <ø> (-0.09%) ⬇️
appsec-macos 58.50% <ø> (-0.07%) ⬇️
appsec-mongodb-core 49.31% <ø> (-0.08%) ⬇️
appsec-mongoose 50.00% <ø> (-0.08%) ⬇️
appsec-mysql 51.39% <ø> (-0.08%) ⬇️
appsec-node-serialize 43.58% <ø> (-0.09%) ⬇️
appsec-passport 48.15% <ø> (-0.09%) ⬇️
appsec-postgres 51.15% <ø> (-0.08%) ⬇️
appsec-sourcing 42.92% <ø> (-0.09%) ⬇️
appsec-template 43.75% <ø> (-0.09%) ⬇️
appsec-ubuntu 58.58% <ø> (-0.07%) ⬇️
appsec-windows 58.36% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-bluebird 32.32% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-body-parser 40.85% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-child_process 37.94% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-cookie-parser 34.55% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express 34.89% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.69% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-session 40.47% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-fs 31.92% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-generic-pool 30.19% <ø> (ø)
instrumentations-instrumentation-http 39.66% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.33% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mongoose 33.68% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.59% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mysql2 38.44% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport 44.46% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 44.11% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.67% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.85% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise 32.25% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.26% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-q 32.30% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-url 32.22% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.27% <ø> (-0.11%) ⬇️
llmobs-ai 41.48% <ø> (-0.10%) ⬇️
llmobs-anthropic 40.67% <ø> (-0.10%) ⬇️
llmobs-bedrock 39.55% <ø> (-0.09%) ⬇️
llmobs-google-genai 40.16% <ø> (-0.09%) ⬇️
llmobs-langchain 39.70% <ø> (-0.08%) ⬇️
llmobs-openai 44.51% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 40.39% <ø> (-0.15%) ⬇️
platform-core 29.71% <ø> (ø)
platform-esbuild 32.89% <ø> (ø)
platform-instrumentations-misc 40.53% <ø> (ø)
platform-shimmer 36.14% <ø> (ø)
platform-unit-guardrails 31.27% <ø> (ø)
plugins-azure-event-hubs 24.02% <ø> (ø)
plugins-azure-service-bus 23.42% <ø> (ø)
plugins-bullmq 43.78% <ø> (-0.10%) ⬇️
plugins-cassandra 38.10% <ø> (-0.10%) ⬇️
plugins-cookie 25.08% <ø> (ø)
plugins-cookie-parser 24.87% <ø> (ø)
plugins-crypto 24.72% <ø> (ø)
plugins-dd-trace-api 38.49% <ø> (-0.11%) ⬇️
plugins-express-mongo-sanitize 25.04% <ø> (ø)
plugins-express-session 24.83% <ø> (ø)
plugins-fastify 42.58% <ø> (-0.10%) ⬇️
plugins-fetch 38.64% <ø> (-0.10%) ⬇️
plugins-fs 38.74% <ø> (-0.11%) ⬇️
plugins-generic-pool 24.06% <ø> (ø)
plugins-google-cloud-pubsub 45.79% <ø> (-0.09%) ⬇️
plugins-grpc 41.32% <ø> (-0.10%) ⬇️
plugins-handlebars 25.08% <ø> (ø)
plugins-hapi 40.49% <ø> (-0.10%) ⬇️
plugins-hono 40.75% <ø> (-0.10%) ⬇️
plugins-ioredis 38.54% <ø> (-0.11%) ⬇️
plugins-knex 24.80% <ø> (ø)
plugins-ldapjs 22.61% <ø> (ø)
plugins-light-my-request 24.48% <ø> (ø)
plugins-limitd-client 32.62% <ø> (-0.11%) ⬇️
plugins-lodash 24.13% <ø> (ø)
plugins-mariadb 39.65% <ø> (-0.10%) ⬇️
plugins-memcached 38.28% <ø> (-0.11%) ⬇️
plugins-microgateway-core 39.51% <ø> (-0.10%) ⬇️
plugins-moleculer 40.88% <ø> (-0.10%) ⬇️
plugins-mongodb 39.52% <ø> (-0.10%) ⬇️
plugins-mongodb-core 39.15% <ø> (-0.10%) ⬇️
plugins-mongoose 39.20% <ø> (-0.10%) ⬇️
plugins-multer 24.83% <ø> (ø)
plugins-mysql 39.26% <ø> (-0.14%) ⬇️
plugins-mysql2 39.39% <ø> (-0.10%) ⬇️
plugins-node-serialize 25.12% <ø> (ø)
plugins-opensearch 37.93% <ø> (-0.10%) ⬇️
plugins-passport-http 24.91% <ø> (ø)
plugins-postgres 35.78% <ø> (-0.09%) ⬇️
plugins-process 24.72% <ø> (ø)
plugins-pug 25.08% <ø> (ø)
plugins-redis 39.02% <ø> (-0.11%) ⬇️
plugins-router 43.36% <ø> (-0.10%) ⬇️
plugins-sequelize 23.66% <ø> (ø)
plugins-test-and-upstream-amqp10 38.61% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-amqplib 43.97% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.34% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.89% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-bunyan 33.94% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-connect 41.17% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.29% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.66% <ø> (-0.18%) ⬇️
plugins-test-and-upstream-protobufjs 39.12% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-rhea 44.22% <ø> (-0.13%) ⬇️
plugins-undici 39.43% <ø> (-0.10%) ⬇️
plugins-url 24.72% <ø> (ø)
plugins-valkey 38.20% <ø> (-0.11%) ⬇️
plugins-vm 24.72% <ø> (ø)
plugins-winston 34.31% <ø> (-0.10%) ⬇️
plugins-ws 42.29% <ø> (-0.10%) ⬇️
profiling-macos 40.04% <ø> (-0.48%) ⬇️
profiling-ubuntu 40.17% <ø> (-0.10%) ⬇️
profiling-windows 41.77% <ø> (+0.26%) ⬆️
serverless-azure-functions-client 23.75% <ø> (ø)
serverless-azure-functions-eventhubs 23.75% <ø> (ø)
serverless-azure-functions-servicebus 23.75% <ø> (ø)

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.

@watson watson marked this pull request as ready for review February 4, 2026 11:39
@watson watson requested review from a team as code owners February 4, 2026 11:39
@tylfin tylfin requested review from ajwerner and jpbempel February 11, 2026 16:25
@tylfin
Copy link
Copy Markdown
Member

tylfin commented Feb 11, 2026

cc @ajwerner added you to take a peak since you're concurrently working on the Go implementation

@watson watson requested a review from BridgeAR February 12, 2026 11:30
jpbempel
jpbempel previously approved these changes Feb 12, 2026
BridgeAR
BridgeAR previously approved these changes Feb 12, 2026
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM, just left some nits.

I can not say much about the domain knowledge though :)

for (const captureExpr of probe.captureExpressions) {
const limits = {
maxReferenceDepth: captureExpr.capture?.maxReferenceDepth ??
probe.capture?.maxReferenceDepth ?? DEFAULT_MAX_REFERENCE_DEPTH,
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.

Nit: these fallbacks are accessed constantly on each iteration in a worst case while we already have the values if probe.captureSnapshot is defined and we could just unconditionally define the object for easier access and assign probe.capture to that object, if needed. That would be a tad nicer to read and we do not need to access the variables multiple times in a worst case.

Copy link
Copy Markdown
Collaborator Author

@watson watson Feb 13, 2026

Choose a reason for hiding this comment

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

I did it this way to avoid unnecessary object creation. If probe.captureSnapshot is not true, the probe.capture object is never going to be used, so there's no need to create it. I figured this one time penalty when adding the breakpoint was better than the extra object being created.

The best alternative that I can find is this, though it still creates the extra object:

+  const capture = {
+    maxReferenceDepth: probe.capture?.maxReferenceDepth ?? DEFAULT_MAX_REFERENCE_DEPTH,
+    maxCollectionSize: probe.capture?.maxCollectionSize ?? DEFAULT_MAX_COLLECTION_SIZE,
+    maxFieldCount: probe.capture?.maxFieldCount ?? DEFAULT_MAX_FIELD_COUNT,
+    maxLength: probe.capture?.maxLength ?? DEFAULT_MAX_LENGTH,
+  }
+
   if (probe.captureSnapshot) {
-    probe.capture = {
-      maxReferenceDepth: probe.capture?.maxReferenceDepth ?? DEFAULT_MAX_REFERENCE_DEPTH,
-      maxCollectionSize: probe.capture?.maxCollectionSize ?? DEFAULT_MAX_COLLECTION_SIZE,
-      maxFieldCount: probe.capture?.maxFieldCount ?? DEFAULT_MAX_FIELD_COUNT,
-      maxLength: probe.capture?.maxLength ?? DEFAULT_MAX_LENGTH,
-    }
+    probe.capture = capture
   }
 
   if (probe.captureExpressions?.length > 0) {
     probe.compiledCaptureExpressions = []
     for (const captureExpr of probe.captureExpressions) {
       const limits = {
-        maxReferenceDepth: captureExpr.capture?.maxReferenceDepth ??
-          probe.capture?.maxReferenceDepth ?? DEFAULT_MAX_REFERENCE_DEPTH,
-        maxCollectionSize: captureExpr.capture?.maxCollectionSize ??
-          probe.capture?.maxCollectionSize ?? DEFAULT_MAX_COLLECTION_SIZE,
-        maxFieldCount: captureExpr.capture?.maxFieldCount ??
-          probe.capture?.maxFieldCount ?? DEFAULT_MAX_FIELD_COUNT,
-        maxLength: captureExpr.capture?.maxLength ??
-          probe.capture?.maxLength ?? DEFAULT_MAX_LENGTH,
+        maxReferenceDepth: captureExpr.capture?.maxReferenceDepth ?? capture.maxReferenceDepth,
+        maxCollectionSize: captureExpr.capture?.maxCollectionSize ?? capture.maxCollectionSize,
+        maxFieldCount: captureExpr.capture?.maxFieldCount ?? capture.maxFieldCount,
+        maxLength: captureExpr.capture?.maxLength ?? capture.maxLength,
       }

Do you think the tradeoff of this implementation is better than the current one?

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.

I can not tell how likely either case is, so I think it is best for you to decide upon that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A probe is not supposed to have both probe.captureSnapshot: true and probe.captureExpressions.length > 0 at the same time. Those should be mutually exclusive. Some customers will lean heavily towards using Capture Expressions all the time, others will only use snapshots, others will not use any of those 🤷 I'll leave it as is for now.

limits,
})
} catch (err) {
throw new Error(
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.

Are we interested in the stack trace? If not, what about using Error.stackTraceLimit = 0 for these cases? I am unsure how likely these are though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We use this pattern throughout the devtools_client worker, and it can be good to have the stack trace so you don't have to rely on the error message being unique enough so that you can find it without the stack trace. Also, it can sometimes help identify which version a given error comes from if the lines have moved around between versions and you somehow don't have the exact version number.


if (probe.captureSnapshot) {
if (captureErrors?.length > 0) {
if (fatalSnapshotErrors && fatalSnapshotErrors.length > 0) {
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.

Nit

Suggested change
if (fatalSnapshotErrors && fatalSnapshotErrors.length > 0) {
if (fatalSnapshotErrors?.length > 0) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

😂 Yeah I know. I did this mainly to appease TS, as it complained about doing undefined > 0

Add support for capturing specific expressions in log probes as an
alternative to full snapshot capture. This allows users to precisely
define which data they want to collect, addressing the 1MB Event
Platform payload limit issue.

When capture expressions are defined, only those expressions are
evaluated and serialized instead of capturing the entire object
graph of local variables, arguments, and fields. Each expression can
optionally override the default capture limits (depth, collection
size, field count, and string length).

The implementation distinguishes between transient evaluation errors
(like undefined variables) and fatal errors (like protocol failures),
allowing some expressions to succeed even when others fail. Fatal
errors disable capture expressions for the probe until it's
re-applied, preventing repeated failures.

Time budget enforcement is respected across all expressions. If the
timeout is reached while evaluating expressions, any remaining
unevaluated expressions are still included in the snapshot with a
notCapturedReason indicating the timeout was exceeded.
@watson watson dismissed stale reviews from BridgeAR and jpbempel via 819f73e February 13, 2026 12:37
@watson watson force-pushed the watson/DEBUG-5011/capture-expressions branch from 90ae293 to 819f73e Compare February 13, 2026 12:37
@watson watson enabled auto-merge (squash) February 13, 2026 12:41
@watson watson merged commit 015654a into master Feb 13, 2026
733 of 790 checks passed
@watson watson deleted the watson/DEBUG-5011/capture-expressions branch February 13, 2026 12:52
dd-octo-sts bot pushed a commit that referenced this pull request Feb 14, 2026
Add support for capturing specific expressions in log probes as an
alternative to full snapshot capture. This allows users to precisely
define which data they want to collect, addressing the 1MB Event
Platform payload limit issue.

When capture expressions are defined, only those expressions are
evaluated and serialized instead of capturing the entire object
graph of local variables, arguments, and fields. Each expression can
optionally override the default capture limits (depth, collection
size, field count, and string length).

The implementation distinguishes between transient evaluation errors
(like undefined variables) and fatal errors (like protocol failures),
allowing some expressions to succeed even when others fail. Fatal
errors disable capture expressions for the probe until it's
re-applied, preventing repeated failures.

Time budget enforcement is respected across all expressions. If the
timeout is reached while evaluating expressions, any remaining
unevaluated expressions are still included in the snapshot with a
notCapturedReason indicating the timeout was exceeded.
@dd-octo-sts dd-octo-sts bot mentioned this pull request Feb 14, 2026
juan-fernandez pushed a commit that referenced this pull request Feb 18, 2026
Add support for capturing specific expressions in log probes as an
alternative to full snapshot capture. This allows users to precisely
define which data they want to collect, addressing the 1MB Event
Platform payload limit issue.

When capture expressions are defined, only those expressions are
evaluated and serialized instead of capturing the entire object
graph of local variables, arguments, and fields. Each expression can
optionally override the default capture limits (depth, collection
size, field count, and string length).

The implementation distinguishes between transient evaluation errors
(like undefined variables) and fatal errors (like protocol failures),
allowing some expressions to succeed even when others fail. Fatal
errors disable capture expressions for the probe until it's
re-applied, preventing repeated failures.

Time budget enforcement is respected across all expressions. If the
timeout is reached while evaluating expressions, any remaining
unevaluated expressions are still included in the snapshot with a
notCapturedReason indicating the timeout was exceeded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Dynamic Instrumentation & Live Debugger semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants