Repository navigation
✨ [DEBUG-6504] Run the Live Debugger without 'unsafe-eval' in the page CSP - #5226
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
Conversation
…e CSP The Live Debugger compiled probe conditions, message templates and capture expressions with `new Function`. That only works if the page CSP allows 'unsafe-eval', which many applications won't add. Each expression AST is now compiled once into nested closures, so no code is generated at runtime. Evaluation keeps the same semantics and side-effect guards, and the shared expression test table still passes. - Add an e2e test that runs a condition, a template and a capture expression on a page whose CSP doesn't allow 'unsafe-eval'. It calls the instrumented function from a page task, because Chromium skips the CSP eval check for code that page.evaluate() runs. - Remove the CSP section from the README and the acorn dev dependency that the generated-code tests used. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 52fe33a | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
Probe expressions referencing classic-script global let, const, or class bindings regress: the new resolver throws ReferenceError or incorrectly reports them as undefined. A focused reproduction confirmed that the base evaluator resolves these bindings successfully.
🤖 Bits Code Review · Commit 4f7606c
`any`, `all` and `filter` looked up `@it`, `@key` and `@value` by name on every item, through the same property access as every other reference, so V8 couldn't optimize it. They're now read from named properties of the iteration, which roughly halves the cost per item. Also document that the top-level let, const and class declarations of classic scripts can't be resolved without evaluated code. Environment: Datadog workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52fe33a0db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
Motivation
The Live Debugger only worked on pages whose Content Security Policy allows
'unsafe-eval', because it compiled probe conditions, message templates and capture expressions withnew Function. Many applications won't loosen their CSP to use a debugger. With this PR, the Live Debugger works without'unsafe-eval'.Jira: DEBUG-6504
Changes
Each expression AST is now compiled once into nested closures, so no code is generated at runtime. Evaluation keeps the same semantics and side-effect guards (getters, coercion,
Map/Setaccess), and the shared expression test table still passes.A few edge cases behave differently. Please check them:
thiswith no receiver now evaluates toundefined. It used to be the global object.stroracc, or named like a built-in such asArrayorMap, no longer break expressions. Before, the generated helpers shadowed them.ReferenceErrormessages are now the same in every browser (foo is not defined).let,constandclassdeclarations of classic (non-module) scripts can't be referenced anymore. They aren't properties ofwindow, and only evaluated code can read them, so there's no way around this without'unsafe-eval'. Globals declared withvarorfunction, and properties ofwindow, still work. Module-scoped and bundler-scoped variables never worked.Other changes:
'unsafe-eval'. It fails onmain. It calls the instrumented function from a page task because Chromium skips the CSP eval check for code thatpage.evaluate()runs. That's why the existing debugger e2e tests passed despite the requirement.acorndev dependency that the generated-code tests used is gone.Benchmarks
Most evaluations are faster, and the first hit of a probe is 7–24 times faster because nothing has to be parsed or compiled.
any,allandfilterare slower than onmainfrom roughly 20 items up. Each item costs about 35 ns instead of about 2.5 ns, because every AST node is a function call that V8 can't merge the way it optimizes generated code. Reading@it,@keyand@valuefrom named properties instead of looking them up by name (second commit) already brought that down from about 58 ns. Conditions only run on hits that pass sampling, and templates and capture expressions only run when a snapshot is taken.mainx > 5user.name == "John" && len(items) >= 3startsWith(s, "foo") && matches(s, "[0-9]+")any(items, @it > 1e9), 10 itemsany(items, @it > 1e9), 100 itemsany(items, @it > 1e9), 1000 itemsmainx > 5user.name == "John" && len(items) >= 3startsWith(s, "foo") && matches(s, "[0-9]+")How these were measured:
mainnumbers include its wrapper, which spreads the context into a cachedFunctionper set of context keys.anypredicate never matches, so it evaluates every item.Test instructions
To see the old failure, run the e2e test against
mainwith onlytest/e2e/scenario/debugger.scenario.tsfrom this branch.Checklist
Reviewed with sol-loop: 1 round with gpt-6.1-sol on both commits (52fe33a). Sol verdict: approved
Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.