-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
536f84d
Add source code context injection
amortemousque b9729fe
Make @DataDog/rum-browser of packages/plugins/rum
amortemousque 8bf50f8
Remove debug logs
amortemousque 223c420
Simplify test + use npm browser SDK version
amortemousque 76b01a3
Update SDK version in rum plugin
amortemousque 906889e
Update yarn cache
amortemousque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file renamed
BIN
+585 KB
...core-npm-6.24.0-e883c4fc19-601add9977.zip → ...core-npm-6.26.0-00db60a2f7-c5a84b637d.zip
Binary file not shown.
Binary file renamed
BIN
+717 KB
...core-npm-6.24.0-1e2bc22c73-eea74ab7e6.zip → ...core-npm-6.26.0-5d3f0e2bd2-2d3423c324.zip
Binary file not shown.
Binary file removed
BIN
-481 KB
.yarn/cache/@datadog-browser-rum-npm-6.24.0-1963fb8d4d-c1b7fc0687.zip
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2019-Present Datadog, Inc. | ||
|
|
||
| import type { SourceCodeContextOptions } from './types'; | ||
|
|
||
| export const DEFAULT_SOURCE_CODE_CONTEXT_VARIABLE = 'DD_SOURCE_CODE_CONTEXT' as const; | ||
|
|
||
| // The source code context snippet - single injection with function definition and call | ||
| // SSR-safe: checks window before accessing, never throws | ||
| // | ||
| // Unminified version: | ||
| // (function(c, n) { | ||
| // try { | ||
| // if (typeof window === 'undefined') return; | ||
| // var w = window, | ||
| // m = w[n] = w[n] || {}, | ||
| // s = new Error().stack; | ||
| // s && (m[s] = c) | ||
| // } catch (e) {} | ||
| // })(context, variableName); | ||
| export const getSourceCodeContextSnippet = (context: SourceCodeContextOptions): string => { | ||
| return `(function(c,n){try{if(typeof window==='undefined')return;var w=window,m=w[n]=w[n]||{},s=new Error().stack;s&&(m[s]=c)}catch(e){}})(${JSON.stringify(context)},${JSON.stringify(DEFAULT_SOURCE_CODE_CONTEXT_VARIABLE)});`; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2019-Present Datadog, Inc. | ||
|
|
||
| /* eslint-env browser */ | ||
| import { datadogRum } from '@datadog/browser-rum'; | ||
|
|
||
| // Used by Playwright tests to ensure the chunk module has been evaluated. | ||
| window.chunkLoaded = true; | ||
|
|
||
| const $ = document.querySelector.bind(document); | ||
|
|
||
| $('#trigger_chunk_error').addEventListener('click', () => { | ||
| datadogRum.addError(new Error('chunk_error')); | ||
| }); |
21 changes: 21 additions & 0 deletions
21
packages/tests/src/e2e/sourceCodeContext/project/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <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> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>Source Code Context Test - {{bundler}}</h1> | ||
| <p>Testing source code context injection.</p> | ||
|
|
||
| <button id="load_chunk" role="button">Load chunk</button> | ||
|
|
||
| <button id="trigger_entry_error" role="button">Entry error</button> | ||
| <button id="trigger_chunk_error" role="button">Chunk error</button> | ||
|
|
||
| <script type="module" src="./dist/{{bundler}}.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2019-Present Datadog, Inc. | ||
|
|
||
| /* eslint-env browser */ | ||
|
|
||
| import { datadogRum } from '@datadog/browser-rum'; | ||
|
|
||
| const $ = document.querySelector.bind(document); | ||
|
|
||
| $('#trigger_entry_error').addEventListener('click', () => { | ||
| datadogRum.addError(new Error('entry_error')); | ||
| }); | ||
|
|
||
| $('#load_chunk').addEventListener('click', async () => { | ||
| await import('./chunk.js'); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
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.
hum, maybe we add could have everything optional then 🤔
And later add
contextin the options as well.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.
Yeah, for now the use case is ownership assignment. Since we don’t have other features to inject yet, I’d rather make the field required to prevent empty options. We can definitely reassess once we add new capabilities.