Skip to content

Conversation

@amortemousque
Copy link

What and why?

This PR adds source code context injection capabilities to the RUM plugin, enabling customers to identify which microfrontend originates each RUM event in their applications. It focuses on setups with separated bundles loaded via dynamic imports (e.g., module federation) by injecting source code metadata at entry points.

How?

  • New sourceCodeContext option in RUM plugin config that accepts service (required) and version (optional) to identify microfrontend bundles
  • Injects minified, SSR-safe snippet that creates DD_SOURCE_CODE_CONTEXT global variable mapping stack traces to service/version metadata
  • Fixed injection plugin to support both production builds and watch/dev mode by adding watchRun hook
  • Added validation requiring service field and ensuring proper type checking
  • Comprehensive E2E tests covering context injection, stack trace mapping, and error handling across multiple bundlers

@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch from acd05a6 to f38fce4 Compare December 18, 2025 09:06
@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch from f38fce4 to 761d68d Compare December 18, 2025 09:28
Copy link
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

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

Looks super good.
Thanks for tackling this.

Do you think you could also update ownership of the plugin?

packages/plugins/rum @yoannmoinet

I mostly had small comments.

Copy link
Member

Choose a reason for hiding this comment

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

Is this file accidentally duplicated?

return toReturn;
}

const cfg = validatedOptions.sourceCodeContext as SourceCodeContextOptions;
Copy link
Member

Choose a reason for hiding this comment

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

Would this work?
I'm not a super fan of as casting.

Suggested change
const cfg = validatedOptions.sourceCodeContext as SourceCodeContextOptions;
const cfg: SourceCodeContextOptions = validatedOptions.sourceCodeContext;

const cfg = validatedOptions.sourceCodeContext as SourceCodeContextOptions;

if (!cfg?.service || typeof cfg.service !== 'string') {
toReturn.errors.push(`Missing ${red('"sourceCodeContext.service"')}.`);
Copy link
Member

Choose a reason for hiding this comment

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

To avoid any confusion from user's standpoint.

Suggested change
toReturn.errors.push(`Missing ${red('"sourceCodeContext.service"')}.`);
toReturn.errors.push(`Missing ${red('"rum.sourceCodeContext.service"')}.`);

Comment on lines +45 to +47
{
entry: bundlers.reduce((acc, bundler) => ({ ...acc, [bundler]: './index.js' }), {}),
},
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary?
I think this is the default.

const bundlerEntry = buildConfigOverride?.entry?.[bundler] || './index.js';

Suggested change
{
entry: bundlers.reduce((acc, bundler) => ({ ...acc, [bundler]: './index.js' }), {}),
},

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.

3 participants