Skip to content

fix(live-debugger): exclude params from locals in instrumented code#335

Draft
watson wants to merge 1 commit intowatson/DEBUG-5465/inject-version-at-runtimefrom
watson/DEBUG-5465/do-not-treat-args-as-locals
Draft

fix(live-debugger): exclude params from locals in instrumented code#335
watson wants to merge 1 commit intowatson/DEBUG-5465/inject-version-at-runtimefrom
watson/DEBUG-5465/do-not-treat-args-as-locals

Conversation

@watson
Copy link
Copy Markdown
Contributor

@watson watson commented Apr 30, 2026

What and why?

The live debugger build plugin was duplicating function parameters in the snapshot's locals section. When an instrumented function was captured at its return point, the locals object sent to the browser SDK contained both the function's local variable declarations and its parameters — even though parameters were already captured separately in the arguments object. This caused redundant data in debugger snapshots.

How?

Transform change (scopeTracker / index.ts):

  • Changed exitVars (the locals helper) from getVariableNames(node, true, true) to getVariableNames(node, false, true), so it only collects local variable declarations — not function parameters.
  • When there are no local variables, the locals helper and its argument to $dd_return are omitted entirely instead of passing an empty object, reducing instrumented bundle size.
  • When there are no function parameters, the args helper is also omitted and the argument to $dd_entry/$dd_return/$dd_throw is dropped. If locals are present but params are not, undefined is passed as a positional placeholder for args in $dd_return.

Generated output for each case:

Scenario $dd_entry / $dd_throw $dd_return
No params, no locals (probes, this) (probes, rv, this)
No params, has locals (probes, this) (probes, rv, this, undefined, $dd_l())
Has params, no locals (probes, this, $dd_e()) (probes, rv, this, $dd_e())
Has params, has locals (probes, this, $dd_e()) (probes, rv, this, $dd_e(), $dd_l())

Note: This change requires a corresponding update in the browser-sdk to default the args and locals parameters to {} in onEntry, onReturn, and onThrow, so that omitted arguments are handled gracefully.

The locals helper passed to $dd_return included function parameters
alongside actual local variables, causing the snapshot to duplicate
argument values in both the arguments and locals sections.

Change exitVars to only collect local variable declarations (not params),
and omit the args/locals helpers entirely when they would be empty to
reduce instrumented bundle size.
Copy link
Copy Markdown
Contributor Author

watson commented Apr 30, 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.

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