-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Add ContextLines integration for html-embedded JS stack frames
#8670
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
Conversation
size-limit report 📦
|
mydea
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.
nice one!
cb37c44 to
55531d7
Compare
55531d7 to
5bea408
Compare
|
Hmm I'm realizing that we should move this to @sentry/integrations because right now it'd be included by default in the CDN bundles. Instead it should be its own CDN bundle that users can add to their setup if they're using our CDN/loader. |
ahh, makes sense! That's fine I'd say 👍 |
069cfec to
cbfaa35
Compare
| const html = doc.documentElement.innerHTML; | ||
|
|
||
| const htmlLines = ['<!DOCTYPE html>', '<html>', ...html.split('\n'), '</html>']; | ||
| if (!htmlLines.length) { |
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.
m: This is always gonna evaluate to false if we have these default values in htmlLines.
Bringing be to a different point: Why do we have these default values? Would it make sense to use document.documentElement.outerHTML instead?
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.
Good catch, I'll adjust the length check!
I started with outerHTML but for some reason, the resulting string is formatted differently (less line breaks) as when using innerHTML.
|
Or even |
To get source context around browser-side stack frames, the Sentry backend tries to download the JS files during ingestion/symbolication and applies the context lines then. However, sometimes our backend cannot access the requested HTML (or gets a different version of it) e.g. due to missing authentication credentials. Therefore, this PR adds a new browser integration -
ContextLines.It can be used to add source code lines to and around stack frames that point towards JS in html files (e.g. in
<script>tags oronclickhandlers). The integration does not apply these context lines to frames pointing to actual script files as these cannot be accessed within the browser.Limitations:
onclickhandlers) have the wrong line number, as the line number of the error isn't relative to the entire HTML document but to the isolated script."Script error."which we filter out inInboundFilters. These errors continue to not get reported to Sentry by default.documentElement.innerHtml. Using this instead ofouterHtmland adding tags manually seems to have improved stability in my testing but I'm not sure if it does the trick for every browser.Given the limited use case and the additional bundle size costs, we're not going to enable this integration by default but we'll document it and let users opt in to use it. Hence, the package is also exported from
@sentry/integrationsinstead of@sentry/browserand it won't be part of the browser CDN bundles.closes #8656