Skip to content

✨ [RUM-16925] attach debug IDs from DD_SOURCE_CODE_CONTEXT to error and long task events#4812

Merged
amortemousque merged 13 commits into
mainfrom
aymeric/add-debug-id
Jul 3, 2026
Merged

✨ [RUM-16925] attach debug IDs from DD_SOURCE_CODE_CONTEXT to error and long task events#4812
amortemousque merged 13 commits into
mainfrom
aymeric/add-debug-id

Conversation

@amortemousque

@amortemousque amortemousque commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Part of the sourcemap unminification project. When a Datadog bundler plugin is used, it injects DD_SOURCE_CODE_CONTEXT on the window with per-bundle metadata (service, version, debug ID). This PR makes the RUM SDK read the ddDebugId field 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

  • Move sourceCodeContext from browser-rum-core to browser-core so both RUM and later Logs SDK can access it.
  • Rename the MFE-specific context hook to sourceCodeMfeContext (clearer scope)
  • In computeRawError: resolve debug_ids by looking up all stack frame URLs in DD_SOURCE_CODE_CONTEXT and attach them as _dd.debug_ids on error events
  • In longTaskCollection: same lookup on script.sourceURL for Long Animation Frame events

Test instructions

  1. Set window.DD_SOURCE_CODE_CONTEXT with a stack entry whose top-frame URL matches a script URL on the page and a ddDebugId value
  2. Trigger an error or long task from that script
  3. Verify the intake event has _dd.debug_ids: { [scriptUrl]: debugId }

The E2E tests cover both flows automatically (yarn test:e2e -g "debug ID").

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

amortemousque and others added 2 commits June 19, 2026 15:31
- 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>
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 19, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 74.07%
Overall Coverage: 77.20% (+0.02%)

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 19, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.25 KiB 172.67 KiB +427 B +0.24%
Rum Profiler 8.22 KiB 8.22 KiB 0 B 0.00%
Rum Recorder 21.14 KiB 21.14 KiB 0 B 0.00%
Logs 54.62 KiB 55.42 KiB +813 B +1.45%
Rum Slim 130.09 KiB 130.78 KiB +713 B +0.54%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@amortemousque amortemousque changed the title ✨ attach debug IDs from DD_SOURCE_CODE_CONTEXT to error and long task events ✨ [RUM-16925] attach debug IDs from DD_SOURCE_CODE_CONTEXT to error and long task events Jun 22, 2026
…uota_reason on profiling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amortemousque amortemousque force-pushed the aymeric/add-debug-id branch from 0dc95c6 to 5fa0ed2 Compare June 22, 2026 19:49
@amortemousque amortemousque marked this pull request as ready for review June 23, 2026 14:10
@amortemousque amortemousque requested a review from a team as a code owner June 23, 2026 14:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/browser-core/src/domain/sourceCodeContext.ts Outdated
Comment thread packages/browser-rum-core/src/domain/error/errorCollection.ts
Comment thread packages/browser-core/src/domain/error/error.ts Outdated
Comment thread packages/browser-core/src/domain/sourceCodeContext.ts
rgaignault
rgaignault previously approved these changes Jun 24, 2026
Comment thread packages/browser-rum-core/src/domain/contexts/sourceCodeContext.ts
Comment thread packages/browser-core/src/domain/sourceCodeContext.spec.ts Outdated
return stackTrace.stack.map((frame) => frame.url).filter((url): url is string => !!url)
}

export function computeRawError({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Suggestion : since logs is not using debug ids, maybe we could add a flag ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "add a flag"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant adding a param that only RUM passes, so the lookup is skipped for Logs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

@rgaignault rgaignault self-requested a review June 24, 2026 14:25
@rgaignault rgaignault dismissed their stale review June 24, 2026 14:26

Commenting

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/browser-core/src/domain/error/error.ts Outdated
Comment thread test/apps/microfrontend/webpack.app1.js
Comment thread test/e2e/scenario/microfrontend.scenario.ts Outdated
Comment thread packages/browser-rum-core/src/domain/error/errorCollection.ts
chatgpt-codex-connector[bot]

This comment was marked as spam.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent dependency cycle between error and telemetry modules.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@amortemousque amortemousque force-pushed the aymeric/add-debug-id branch from 638373b to a894cd5 Compare June 25, 2026 18:47
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amortemousque amortemousque force-pushed the aymeric/add-debug-id branch from a894cd5 to d95c6a8 Compare June 25, 2026 19:13
… 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>
Comment thread packages/browser-core/src/domain/sourceCodeContext.ts
Comment thread packages/browser-core/src/domain/sourceCodeContext.ts Outdated
expect(getSourceCodeContext(url)).toBeUndefined()
})

it('should ignore updates to an existing URL after it has been read', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question: ‏what is the intent for this cache?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread packages/browser-core/src/domain/error/error.ts Outdated
import { SKIPPED } from '@datadog/js-core/assembly'
import type { DefaultRumEventAttributes, AssembleHookParams, AssembleHook } from '../hooks'

export function startSourceCodeMfeContext(assembleHook: AssembleHook) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 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.

Comment thread packages/browser-rum-core/src/domain/longTask/longTaskCollection.ts Outdated
Comment thread packages/browser-rum-core/src/domain/error/errorCollection.ts
Comment thread packages/browser-rum-core/src/domain/error/errorCollection.ts
Comment thread test/e2e/scenario/microfrontend.scenario.ts Outdated
amortemousque and others added 3 commits July 2, 2026 09:27
… 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>
chatgpt-codex-connector[bot]

This comment was marked as spam.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/browser-rum-core/src/domain/assembly.ts
amortemousque and others added 4 commits July 2, 2026 15:23
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>

@bcaudan bcaudan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@amortemousque amortemousque merged commit d2c7e30 into main Jul 3, 2026
31 checks passed
@amortemousque amortemousque deleted the aymeric/add-debug-id branch July 3, 2026 09:25
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants