build-plugins
build-plugins copied to clipboard
[RUM-13448] Add source code context injection for microfrontend
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