Skip to content

Conversation

@amortemousque
Copy link
Contributor

@amortemousque amortemousque commented Dec 18, 2025

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 and version
  • Injects minified, SSR-safe snippet that creates DD_SOURCE_CODE_CONTEXT global variable mapping stack traces to service/version metadata
  • E2E tests validating the RUM event enrichment

@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch 2 times, most recently 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.

@BeltranBulbarellaDD
Copy link

Looks good!

@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch from 761d68d to da7caff Compare January 28, 2026 14:43
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 28, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

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

@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch from da7caff to 405d4b4 Compare January 29, 2026 14:54
@amortemousque amortemousque reopened this Jan 29, 2026
@amortemousque amortemousque marked this pull request as ready for review January 29, 2026 14:55
@amortemousque amortemousque force-pushed the aymeric/rum-microfrontend branch from 70018c9 to 536f84d Compare January 29, 2026 15:38
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.

Added some comments.
Nothing too bad.

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" sizes="21x21" href="data:image/svg+xml," />
<title>Source Code Context Test</title>
<script src="https://www.datadoghq-browser-agent.com/us1/v6/datadog-rum.js" type="text/javascript"></script>
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 the Browser SDK?
Not a fan of having a live resource in the tests.
Would the auto injection work instead?

See my other comment about the plugin's setup.

sourceCodeContext: {
service: SERVICE_NAME,
version: SERVICE_VERSION,
},
Copy link
Member

Choose a reason for hiding this comment

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

Related to my other comment, I believe if you added the sdk config here, it would work without having to load the SDK from a distant location.

Suggested change
},
},
sdk: {
applicationId: '123',
clientToken: '123',
},

// eslint-disable-next-line no-throw-literal
throw 'Test error from source code context';
};
});
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I follow how this works and what it does.
Can you explain?

await page.click('#trigger_chunk_error');

const events = await getRUMEvents(page);
console.log(events);
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 still necessary?

Comment on lines +179 to +183
console.log(
events
.filter((event: any) => event.type === 'action')
.map((event: any) => event.action.target),
);
Copy link
Member

Choose a reason for hiding this comment

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

Still necessary?
Same for all the other logs.

Comment on lines +122 to +130
(globalThis as any).DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APP_ID>',
enableExperimentalFeatures: ['source_code_context'],
beforeSend: (event: any) => {
(globalThis as any).rum_events.push(event);
return true;
},
});
Copy link
Member

Choose a reason for hiding this comment

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

If you do the SDK injection, I guess this will need to be updated as well, since you will most likely pass these options to the plugin configuration (except the beforeSend one).

Can this one be added post initialisation?

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.

4 participants