-
Notifications
You must be signed in to change notification settings - Fork 145
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
🐛 [RUM-8429] Report an error when lazy loading the recorder module fails #3326
base: main
Are you sure you want to change the base?
🐛 [RUM-8429] Report an error when lazy loading the recorder module fails #3326
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3326 +/- ##
==========================================
- Coverage 92.95% 92.91% -0.05%
==========================================
Files 297 299 +2
Lines 7840 7851 +11
Branches 1785 1786 +1
==========================================
+ Hits 7288 7295 +7
- Misses 552 556 +4 ☔ View full report in Codecov by Sentry. |
}) | ||
} | ||
|
||
export async function lazyLoadRecorderFrom( |
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.
This helper is here for testing purposes, so that it's possible to replace the real dynamic import with a version that throws a specific error.
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.
Maybe something like this would be simpler to get:
export async function lazyLoadRecorder(importRecorderImpl = importRecorder) {
try {
return await importRecorderImpl()
} catch {
reportScriptLoadingError({
error,
source: 'Recorder',
scriptType: 'module',
})
}
}
async function importRecorder() {
const module = await import(/* webpackChunkName: "recorder" */ './startRecording')
return module.startRecording
}
@@ -261,6 +274,43 @@ describe('makeRecorderApi', () => { | |||
}) | |||
}) | |||
|
|||
describe('while lazy loading the recorder module', () => { | |||
it('should report an error but no telemetry if CSP blocks the module', 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.
Note that the behaviors we're testing for here are the same ones we already have for the compression worker; the lazy loaded recorder module will now report errors in the same way.
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.
💬 suggestion: those two tests should be moved to scriptLoadingError.spec.ts
or lazyLoadRecorder.spec.ts
configuredUrl?: string | undefined | ||
error: unknown | ||
source: string | ||
scriptType: 'module' | 'Worker' |
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.
The casing inconsistency here is a bit funky. I wanted to avoid changing the capitalization of "Worker" in case it would affect our telemetry metrics, but "Module" doesn't really feel right, so I ended up with this compromise.
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 don't think capitalization would affect our telemetry metrics tbh. Same for the verb. I'm fine if we just use a same verb everyone.
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.
Cool! In that case, I'll make things a bit more uniform.
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
}) | ||
} | ||
|
||
export async function lazyLoadRecorderFrom( |
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.
Maybe something like this would be simpler to get:
export async function lazyLoadRecorder(importRecorderImpl = importRecorder) {
try {
return await importRecorderImpl()
} catch {
reportScriptLoadingError({
error,
source: 'Recorder',
scriptType: 'module',
})
}
}
async function importRecorder() {
const module = await import(/* webpackChunkName: "recorder" */ './startRecording')
return module.startRecording
}
@@ -261,6 +274,43 @@ describe('makeRecorderApi', () => { | |||
}) | |||
}) | |||
|
|||
describe('while lazy loading the recorder module', () => { | |||
it('should report an error but no telemetry if CSP blocks the module', 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.
💬 suggestion: those two tests should be moved to scriptLoadingError.spec.ts
or lazyLoadRecorder.spec.ts
`${baseMessage} See documentation at ${DOCS_ORIGIN}/integrations/content_security_policy_logs/#use-csp-with-real-user-monitoring-and-session-replay` | ||
) | ||
} else { | ||
addTelemetryError(error) |
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.
💬 suggestion: I don't think we should report the error as telemetry, as there is high chances that we won't be able to do anything about it. Ex: the recorder fails to load because of a user connectivity issue.
Motivation
Lazy loading the recorder module can fail, either due to a customer-side issue (like a CSP misconfiguration) or due to an issue on our end (like failing to upload the chunk to the CDN). We should report an error when this happens and add telemetry.
The current situation is a bummer since the failure is totally silent; no error is reported anywhere. I spent quite a bit of time over the past couple of days trying to understand why one of my local changes wasn't working. The root cause turned out to be #3324; the problem would've been instantly obvious with the changes in this PR.
Changes
This PR adapts the current error reporting we do when the compression worker fails to load so that it can be used for both the compression worker and the lazy loaded recorder module. We now use the same code in both places, so our existing infrastructure for detecting CSP-related errors can be reused.
Testing
I have gone over the contributing documentation.