Skip to content
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

chore(svelte): Detect and report SvelteKit usage #5594

Merged
merged 4 commits into from Aug 18, 2022

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Aug 17, 2022

This PR adds a SvelteKit detection mechanism to our SDK and inserts a SvelteKit entry into event.modules if we detect that the frontend in which the SDK is used, was rendered by SvelteKit.

To check this, we check for the existence of a div with the id svelte-announcer that's automatically injected into the rendered HTML by SvelteKit. It is used to improve accessibility (see sveltejs/kit#307) but we can leverage it as a SvelteKit detection criterion.

Btw, we're not the first ones who came up with this approach, as it turns out: https://twitter.com/jhewt/status/1359632380483493889

Additionally, this PR introduces a new utils function, getDomElement in which we consolidate the usage of document.querySelector in the SDK. So in addition to using this new function for obtaining the div described above, we now also call it in BrowserTracing to get <meta> tags.

Also added some tests to test the new behaviour and the helper functions. We might want to consider writing an integration test for this feature but this first requires a Svelte SDK integration test infrastructure.

ref: #5573

@Lms24 Lms24 mentioned this pull request Aug 17, 2022
6 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.41 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 60.06 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.98 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 52.92 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.77 KB (0%)
@sentry/browser - Webpack (minified) 64.31 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.79 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.72 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.91 KB (0%)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.28 KB (-0.02% 🔽)

use async to detect sveltekit and add tests

switch to using global evt processor instead of async approach
@Lms24 Lms24 force-pushed the lms-svelte-detect-sveltekit branch from 21f06cf to ec0b276 Compare August 18, 2022 09:07
@Lms24 Lms24 self-assigned this Aug 18, 2022
@Lms24 Lms24 added this to the Svelte SDK milestone Aug 18, 2022
@Lms24 Lms24 changed the title chore(svelte): Detect SvelteKit usage chore(svelte): Detect and report SvelteKit usage Aug 18, 2022
@Lms24 Lms24 marked this pull request as ready for review August 18, 2022 09:27
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the helper!

detectedSvelteKit = isSvelteKitApp();
}
if (detectedSvelteKit) {
event.modules = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does event.modules show up? Is it something that is indexed and we can query for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - it displays in event details page, and is indexed - we can query for it in looker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lforst, it's vaguely documented here

}
if (detectedSvelteKit) {
event.modules = {
svelteKit: '1.0',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - feels weird to write 1.0 as that might not be the correct version. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's weird but we have no way of knowing which SvelteKit version was actually being used (let alone that 1.0 isn't even stable yet). So my train of thought for 1.0 was to simply put there something because afaik we have to supply a version here. But happy to change it to 1.x, 0.x, 0 or whatever. Or maybe something like unknown/n/a ? Though I'm not sure which values are allowed here (for example, how they are indexed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we are able to confidently discover correct SvelteKit version I think we can keep it at 1.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe leave it as latest? Later on we can add in the actual version when we support SvelteKit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My worry about leaving it as 1.0 is that we are going to pollute results when we eventually do support SvelteKit and start adding the proper version number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me. I was also thinking to convert it to a boolean but I don't want to abuse the module field for that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, latest is also sounds good to me. As long as the indexer is happy with it.
Our main objective is to find out if SvelteKit is used or not, making the exact version of it lower prio IMO.

@Lms24 Lms24 force-pushed the lms-svelte-detect-sveltekit branch from 3398cad to aa0dd04 Compare August 18, 2022 14:52
@Lms24 Lms24 merged commit 74db527 into master Aug 18, 2022
@Lms24 Lms24 deleted the lms-svelte-detect-sveltekit branch August 18, 2022 15:15
AbhiPrasad added a commit that referenced this pull request Sep 1, 2022
This PR removes the use of the `Element` DOM type from `@sentry/utils`, introduced with #5594. This breaks `@sentry/node` users that use strict TS configs.

We have to cast the type to `any` to make sure it works in different environments, but we supply a generic argument so that users can specify what type of `Element` will be returned from `querySelector`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants