Skip to content

[Live Debugger] Add 10ms snapshot capture timeout circuit breaker#4512

Draft
watson wants to merge 1 commit intographite-base/4512from
watson/DEBUG-5300/add-max-time-circut-breaker
Draft

[Live Debugger] Add 10ms snapshot capture timeout circuit breaker#4512
watson wants to merge 1 commit intographite-base/4512from
watson/DEBUG-5300/add-max-time-circut-breaker

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Apr 21, 2026

Motivation

Snapshot capture in the Live Debugger serializes JavaScript values synchronously by walking object graphs recursively. For large or deeply nested objects, this can block the main thread for an unacceptable amount of time. We need a circuit breaker that aborts capture when it takes too long, preventing the debugger from degrading application performance.

Changes

Adds a 10ms cooperative timeout to the snapshot capture path in the Browser Debugger SDK.

capture.ts

  • Introduces a CaptureContext interface (deadline + timedOut flag) threaded through capture(), captureFields(), and all internal recursive helpers.
  • Both public functions now require a CaptureContext argument.
  • isTimedOut() checks the flag first (fast path), then calls performance.now() against the deadline. Checks are placed at coarse logical boundaries: before each object property, array element, map entry, set item, and typed array element iteration.
  • When timed out, captureValue returns { type: <real typeof>, notCapturedReason: 'timeout' }, consistent with how all other Datadog tracers handle notCapturedReason.

api.ts

  • Each hook (onEntry, onReturn, onThrow) computes a single deadline before the probe loop and shares it across all probes. This means if one snapshot probe exhausts the budget, subsequent snapshot probes exit immediately, while non-snapshot probes are unaffected.
  • When capture times out, the snapshot event is dropped entirely (not sent).

Test instructions

Run the debugger unit tests:

yarn test:unit packages/debugger

Key test scenarios:

  • Entry/return/throw capture timeout drops the snapshot
  • Non-snapshot probes still fire even after a timeout
  • Shared deadline causes second snapshot probe to exit immediately
  • No active entry leaks when entry capture times out
  • capture() returns the real typeof value (including 'null' not 'object') on timeout

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

Copy link
Copy Markdown
Collaborator Author

watson commented Apr 21, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Apr 21, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 67.39%
Overall Coverage: 76.59% (-0.11%)

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

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented Apr 21, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 179.42 KiB 179.42 KiB 0 B 0.00%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 27.03 KiB 27.03 KiB 0 B 0.00%
Logs 56.80 KiB 56.80 KiB 0 B 0.00%
Rum Slim 135.26 KiB 135.26 KiB 0 B 0.00%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.00545 0.0068 +24.77%
RUM - add action 0.0161 0.0177 +9.94%
RUM - add error 0.013999999999999999 0.0196 +40.00%
RUM - add timing 0.00295 0.0044 +49.15%
RUM - start view 0.01405 0.0183 +30.25%
RUM - start/stop session replay recording 0.0009 0.001 +11.11%
Logs - log message 0.016900000000000002 0.019 +12.43%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 31.53 KiB 31.85 KiB +323 B
RUM - add action 101.84 KiB 106.22 KiB +4.38 KiB
RUM - add timing 32.46 KiB 32.72 KiB +263 B
RUM - add error 104.34 KiB 93.88 KiB -10.46 KiB
RUM - start/stop session replay recording 32.01 KiB 31.12 KiB -907 B
RUM - start view 489.22 KiB 485.94 KiB -3.28 KiB
Logs - log message 99.21 KiB 104.47 KiB +5.26 KiB

🔗 RealWorld

@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 April 21, 2026 07:35
@watson watson force-pushed the graphite-base/4512 branch from bf9a162 to b9da4f3 Compare April 21, 2026 07:39
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 54767dd to 57a3752 Compare April 21, 2026 07:39
@watson watson changed the base branch from graphite-base/4512 to watson/DEBUG-5296/add-live-debugger April 21, 2026 07:39
@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 April 21, 2026 08:17
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 57a3752 to 9967454 Compare April 21, 2026 08:19
@watson watson force-pushed the graphite-base/4512 branch from b9da4f3 to 0040ee8 Compare April 21, 2026 08:19
@watson watson changed the base branch from graphite-base/4512 to watson/DEBUG-5296/add-live-debugger April 21, 2026 08:19
@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 April 21, 2026 09:12
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 9967454 to 6d55f19 Compare April 21, 2026 09:14
@watson watson force-pushed the graphite-base/4512 branch from 0040ee8 to 653aee9 Compare April 21, 2026 09:14
@watson watson changed the base branch from graphite-base/4512 to watson/DEBUG-5296/add-live-debugger April 21, 2026 09:14
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 6d55f19 to 92a1c3c Compare April 21, 2026 09:25
@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 April 22, 2026 12:25
@watson watson force-pushed the graphite-base/4512 branch from 653aee9 to 7d1efe7 Compare April 22, 2026 21:03
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 92a1c3c to 46622ab Compare April 22, 2026 21:03
@watson watson changed the base branch from graphite-base/4512 to watson/DEBUG-5296/add-live-debugger April 22, 2026 21:04
@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 April 23, 2026 10:42
Thread a CaptureContext with a performance.now() deadline through the
capture walker so that snapshot serialization aborts early when the
budget is exceeded. A single deadline is shared across all probes in
a hook invocation; non-snapshot probes are unaffected.

When the timeout fires, the snapshot is dropped entirely and capture
stops at the next logical checkpoint (property, array element, map
entry, etc.). The timeout value uses the real typeof the value,
consistent with how all other Datadog tracers handle notCapturedReason.
@watson watson force-pushed the watson/DEBUG-5300/add-max-time-circut-breaker branch from 46622ab to 79c3335 Compare April 23, 2026 11:00
@watson watson changed the base branch from graphite-base/4512 to watson/DEBUG-5296/add-live-debugger April 23, 2026 11:00
@watson watson changed the base branch from watson/DEBUG-5296/add-live-debugger to graphite-base/4512 May 7, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant