-
Notifications
You must be signed in to change notification settings - Fork 8
[RUM-13448] Add source code context injection for microfrontend #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
f38fce4 to
761d68d
Compare
yoannmoinet
left a comment
There was a problem hiding this 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?
build-plugins/.github/CODEOWNERS
Line 26 in ae68609
| packages/plugins/rum @yoannmoinet |
I mostly had small comments.
packages/tests/src/e2e/sourceCodeContext/sourceCodeContext.spec.ts
Outdated
Show resolved
Hide resolved
|
Looks good! |
761d68d to
da7caff
Compare
This comment has been minimized.
This comment has been minimized.
da7caff to
405d4b4
Compare
70018c9 to
536f84d
Compare
There was a problem hiding this 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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see. I realize I need to make the architecture clearer 🙂
Here’s my reasoning, happy to challenge it.
- I want the tests for this plugin to stay isolated and not depend on another plugin. That’s why I didn’t rely on the SDK injection plugin and instead CDN SDK directly. If you prefer I can use the npm SDK setup?
- For the e2e assertions, I used
beforeSendto capture RUM events instead of intercepting network requests like in other tests. My concern is that compression will soon become mandatory for RUM,beforeSendavoids that complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the isolation part makes total sense.
Could we maybe use nock to intercept this request, and direct it to the locally installed SDK? The project already has a dependency on it.
It's really only about the network call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. I updated the code to use the browser SDK from NPM.
I also removed some tests, following the discussion with Bastien: #255 (comment)
packages/tests/src/e2e/sourceCodeContext/sourceCodeContext.spec.ts
Outdated
Show resolved
Hide resolved
packages/tests/src/e2e/sourceCodeContext/sourceCodeContext.spec.ts
Outdated
Show resolved
Hide resolved
| (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; | ||
| }, | ||
| }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, you can pass beforeSend only in the init API. If the injection does not support it, I can’t use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If needed, you could probably check the events by using the extension callback __ddBrowserSdkExtensionCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d rather avoid a dependency on the internal __ddBrowserSdkExtensionCallback API. It’s more likely to break, even in minor releases. Maybe, it's just me being overcautious 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
BeltranBulbarellaDD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
||
| export type SourceCodeContextOptions = { | ||
| service: string; | ||
| version?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: is there a use case that we want to explicitly support with omitting version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you want to enrich the event with the owner (service) but don’t care about the version or unminification?
Do you think we should enforce the version to prepare customers for the unminification use case?
| (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; | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If needed, you could probably check the events by using the extension callback __ddBrowserSdkExtensionCallback
| expect(chunkAction).toMatchObject({ version: SERVICE_VERSION, service: SERVICE_NAME }); | ||
| }); | ||
|
|
||
| test('Should enrich RUM fetch resources with source code context (service/version)', async ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: It is great to have integrations tests, not sure if we need to have the whole combinatory of cases though, especially in this repo.
If we add more events with source code context, I'd rather only have to update the browser-sdk repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I’ll keep only one test on event enrichment and move all combinations to the browser-sdk repo for easier maintenance.
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "dependencies": { | ||
| "@datadog/browser-rum": "6.26.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the same version already imported in the repo, or update all the other versions to fit that one.
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?