✨ [RUM-16925] attach debug IDs from DD_SOURCE_CODE_CONTEXT to error and long task events#4812
Conversation
- Move sourceCodeContext from browser-rum-core to browser-core so all packages can access it - Rename MFE-specific context to sourceCodeMfeContext - Attach debug IDs (from DD_SOURCE_CODE_CONTEXT) to raw errors and long tasks via stack trace URL lookup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- errors.scenario: verify _dd.debug_ids is populated on error events from DD_SOURCE_CODE_CONTEXT - microfrontend.scenario: verify _dd.debug_ids on MFE runtime errors and LOAf events Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: bc2d73f | Docs | Datadog PR Page | Give us feedback! |
Bundles Sizes Evolution
|
…uota_reason on profiling Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0dc95c6 to
5fa0ed2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fa0ed2a91
ℹ️ 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".
| return stackTrace.stack.map((frame) => frame.url).filter((url): url is string => !!url) | ||
| } | ||
|
|
||
| export function computeRawError({ |
There was a problem hiding this comment.
💬 Suggestion : since logs is not using debug ids, maybe we could add a flag ?
There was a problem hiding this comment.
What do you mean by "add a flag"?
There was a problem hiding this comment.
I meant adding a param that only RUM passes, so the lookup is skipped for Logs
There was a problem hiding this comment.
In practice, stack traces are small (10 frames by default in V8), so the lookup cost is negligible. Also I’ll add debugId to Logs in a follow-up PR :)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b7370a59c
ℹ️ 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".
There was a problem hiding this comment.
Prevent dependency cycle between error and telemetry modules.
638373b to
a894cd5
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
a894cd5 to
d95c6a8
Compare
… ReferenceError In service/web workers (Logs SDK) `window` is undefined; reading it as a bare identifier threw a ReferenceError, dropping the error before it could be reported. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| expect(getSourceCodeContext(url)).toBeUndefined() | ||
| }) | ||
|
|
||
| it('should ignore updates to an existing URL after it has been read', () => { |
There was a problem hiding this comment.
❓ question: what is the intent for this cache?
There was a problem hiding this comment.
This test already existed in the previous sourceCodeContext.ts, so I kept it. IIUC, the rationale was to keep attribution stable throughout the session, even if the URL context is mutated (e.g., when the cache is refreshed or by an unexpected third-party script). Do you think this is unnecessary?
| import { SKIPPED } from '@datadog/js-core/assembly' | ||
| import type { DefaultRumEventAttributes, AssembleHookParams, AssembleHook } from '../hooks' | ||
|
|
||
| export function startSourceCodeMfeContext(assembleHook: AssembleHook) { |
There was a problem hiding this comment.
💬 suggestion: it is a bit implicit right now so it could be interesting to document the intent somewhere:
- Service/version attribution uses only the top frame URL.
- Debug IDs cover all bundles across the full cause chain, not just the top frame.
… test app Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add `_dd.debug_ids` to the modifiable field paths for error and long task events so customers can edit or delete the debug IDs map in beforeSend, the same way they redact error.stack or long_task.scripts[].source_url. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c75e0ff1de
ℹ️ 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".
globalObject moved to @datadog/js-core/util; the stale '../tools/globalObject' path only resolved against leftover build output, breaking the browser-core prepack build and cascading to yarn build:apps. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerate the e2e debug-id/chunk-hash constants, which change with the new plugin's bundle output. All microfrontend e2e tests pass (24/24). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Firefox reports more stack frames than chromium/webkit, so error/long-task events carry extra debug_ids entries. Switch the microfrontend debug_id assertions from toEqual to toMatchObject (subset) to tolerate those extras. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Motivation
Part of the sourcemap unminification project. When a Datadog bundler plugin is used, it injects
DD_SOURCE_CODE_CONTEXTon the window with per-bundle metadata (service, version, debug ID). This PR makes the RUM SDK read theddDebugIdfield from that context and attach it to error and long task events as_dd.debug_ids, enabling the backend to correlate events with uploaded sourcemaps.Changes
sourceCodeContextfrombrowser-rum-coretobrowser-coreso both RUM and later Logs SDK can access it.sourceCodeMfeContext(clearer scope)computeRawError: resolvedebug_idsby looking up all stack frame URLs inDD_SOURCE_CODE_CONTEXTand attach them as_dd.debug_idson error eventslongTaskCollection: same lookup onscript.sourceURLfor Long Animation Frame eventsTest instructions
window.DD_SOURCE_CODE_CONTEXTwith a stack entry whose top-frame URL matches a script URL on the page and addDebugIdvalue_dd.debug_ids: { [scriptUrl]: debugId }The E2E tests cover both flows automatically (
yarn test:e2e -g "debug ID").Checklist