Skip to content

Default args and locals params in debugger snapshot hooks#4609

Draft
watson wants to merge 1 commit into
mainfrom
watson/DEBUG-5296/allow-no-args-or-locals
Draft

Default args and locals params in debugger snapshot hooks#4609
watson wants to merge 1 commit into
mainfrom
watson/DEBUG-5296/allow-no-args-or-locals

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented May 12, 2026

Motivation

The Live Debugger build plugin (in DataDog/build-plugins) generates instrumented code that wraps every monitored function with calls to four global hooks: $dd_probes, $dd_entry, $dd_return, and $dd_throw. The entry/return/throw hooks currently require the build plugin to always pass an args helper, and $dd_return also requires a locals helper, even when:

  • the function has no parameters (nothing to capture as args), or
  • the probe is not configured to capture locals (so locals would always be empty).

Today the plugin works around this by emitting () => ({}) helpers in those cases, which adds dead code to the hot path and inflates the instrumented bundle. Making these parameters optional on the runtime side unlocks a follow-up build-plugin change that simply omits the argument at the call site.

Changes

packages/debugger/src/domain/api.ts:

  • onEntry(probes, self, args)onEntry(probes, self, args = {})
  • onReturn(probes, value, self, args, locals)onReturn(probes, value, self, args = {}, locals = {})
  • onThrow(probes, error, self, args)onThrow(probes, error, self, args = {})

No behavioral change for any existing call site: callers that pass a Record<string, any> (including the build plugin's current $dd_e() / $dd_l() helpers) behave identically. The defaults only kick in when an argument is omitted — which is what the build plugin will start doing for parameter-less functions and probes without local capture in a follow-up.

Notes:

  • args is spread into the context used for condition / message evaluation and into the captured snapshot (captureFields(args, …)). Spreading {} is a no-op, so behavior is preserved.
  • locals in onReturn is treated the same way (...locals + captureFields(locals, …)).
  • This is a pure typing/runtime relaxation; no public API surface changes.

Test instructions

End-to-end behavior with the build plugin will be exercised once the corresponding build-plugins change lands (omitting the trailing args/locals helpers in generated code).

Checklist

  • Tested locally
  • Tested on staging — not applicable; pure runtime relaxation with no protocol or transport change.
  • Added unit tests for this change — covered by the existing api.spec.ts suite; the change is a type-level relaxation (defaulting optional parameters to {}). Happy to add an explicit "called with no args/locals" case if reviewers prefer.
  • Added e2e/integration tests for this change — will be covered end-to-end by the follow-up build-plugins PR that exercises the new call shape.
  • Updated documentation and/or relevant AGENTS.md file — no documented contract changes.

Copy link
Copy Markdown
Collaborator Author

watson commented May 12, 2026

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

cit-pr-commenter-54b7da Bot commented May 12, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 169.51 KiB 169.51 KiB 0 B 0.00%
Rum Profiler 5.97 KiB 5.97 KiB 0 B 0.00%
Rum Recorder 21.23 KiB 21.23 KiB 0 B 0.00%
Logs 54.70 KiB 54.70 KiB 0 B 0.00%
Rum Slim 127.85 KiB 127.85 KiB 0 B 0.00%
Worker 22.99 KiB 22.99 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0031 0.0019 -38.71%
RUM - add action 0.0164 0.0095 -42.07%
RUM - add error 0.0137 0.0101 -26.28%
RUM - add timing 0.0007 0.0005 -28.57%
RUM - start view 0.0151 0.012 -20.53%
RUM - start/stop session replay recording 0.0013 0.0007 -46.15%
Logs - log message 0.0234 0.0194 -17.09%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 38.75 KiB 38.61 KiB -146 B
RUM - add action 64.74 KiB 64.97 KiB +241 B
RUM - add timing 36.82 KiB 37.33 KiB +517 B
RUM - add error 70.81 KiB 69.54 KiB -1.27 KiB
RUM - start/stop session replay recording 41.37 KiB 42.58 KiB +1.22 KiB
RUM - start view 486.34 KiB 483.21 KiB -3.13 KiB
Logs - log message 55.35 KiB 54.48 KiB -884 B

🔗 RealWorld

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

datadog-datadog-prod-us1 Bot commented May 12, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 1 Test failed

cookieAccess document.cookie fallback observable should notify when cookie is changed externally from Chrome Headless 148.0.0.0 (Linux 0.0.0)   View in Datadog   (Fix with Cursor)
Error: Expected spy observer to have been called once. It was called 0 times.
    at <Jasmine>
    at UserContext.<anonymous> (/go/src/github.com/DataDog/browser-sdk/packages/core/src/browser/cookieAccess.spec.ts:179:23 <- /tmp/_karma_webpack_870888/commons.js:359849:33)

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 76.96% (+0.00%)

Useful? React with 👍 / 👎

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

@watson watson force-pushed the watson/DEBUG-5296/use-public-api branch from 7c29372 to 331c32c Compare May 12, 2026 11:43
@watson watson force-pushed the watson/DEBUG-5296/allow-no-args-or-locals branch from 0bcb507 to 1eeda79 Compare May 12, 2026 11:43
@watson watson force-pushed the watson/DEBUG-5296/use-public-api branch from 331c32c to 239ef70 Compare May 12, 2026 14:15
@watson watson force-pushed the watson/DEBUG-5296/allow-no-args-or-locals branch from 1eeda79 to 13d0744 Compare May 12, 2026 14:15
@watson watson changed the base branch from watson/DEBUG-5296/use-public-api to graphite-base/4609 May 12, 2026 15:03
Allow the build plugin to omit empty args/locals arguments from
$dd_entry, $dd_return, and $dd_throw calls by defaulting the
parameters to {} in onEntry, onReturn, and onThrow.
@watson watson force-pushed the watson/DEBUG-5296/allow-no-args-or-locals branch from 13d0744 to 0a9836c Compare May 12, 2026 15:39
@watson watson force-pushed the graphite-base/4609 branch from 239ef70 to 9b44f2f Compare May 12, 2026 15:39
@watson watson changed the base branch from graphite-base/4609 to main May 12, 2026 15:39
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