Skip to content

Commit 15e464a

Browse files
authored
ref(svelte): Update component tracking docs with new withSentryConfig approach (#5649)
This patch updates the Svelte component tracking docs with usage instructions for the new approach we recently introduced to the Svelte SDK. Instead of manually adding a preprocessor to their svelte config, users can now simply wrap their config with a Sentry wrapper function that takes care of adding this preprocessor for them. This new approach allows us to make more changes to the config in the future without asking our users every time to change something in their config.
1 parent dd4a830 commit 15e464a

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

src/platforms/javascript/guides/svelte/features/component-tracking.mdx

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,55 @@ To set up component tracking, you need to configure performance monitoring. For
1313

1414
</Alert>
1515

16-
To get started, add the Sentry `componentTrackingPreprocessor` to your `svelte.config.js` file:
16+
To get started, wrap your Svelte app's config from `svelte.config.js` with our `withSentryConfig` function:
1717

1818
```javascript {tabTitle: svelte.config.js}
19-
import * as Sentry from "@sentry/svelte";
19+
import { withSentryConfig } from "@sentry/svelte";
2020

2121
const config = {
22-
preprocess: [
23-
Sentry.componentTrackingPreprocessor({
24-
// Add the components you want to be tracked to this array.
25-
// Specificy `true` to track all components or `false` to disable
26-
// tracking entirely
27-
// (defaults to `true`)
28-
trackComponents: ["Navbar", "PrimaryButton", "LoginForm"],
29-
// To disable component initialization spans, set this to `false`.
30-
// (defaults to `true`)
31-
trackInit: true,
32-
// To disable component update spans, set this to `false`
33-
// (defaults to `true`)
34-
trackUpdates: false,
35-
}),
36-
// ...
37-
],
38-
// ...
22+
// Your svelte config
23+
compilerOptions: {...},
3924
};
4025

41-
export default config;
26+
export default withSentryConfig(config);
4227
```
4328

44-
This preprocessor is called at application build time. It inserts a function call to a function in the Sentry SDK into the `<script>` tag of your components before your app is compiled and bundled. The called function takes care of recording the spans by using the Svelte component's lifecycle hooks.
29+
This wrapper will insert Sentry's component tracking preprocessor into your config. The preprocessor inserts a function call to a function in the Sentry SDK into the `<script>` tag of your components before your app is compiled and bundled.
30+
31+
### Configuration
32+
33+
Once you add `withSentryConfig` around your Svelte config, our SDK will track all your components by default. If you want to customize which components or lifecycle events should be tracked, you can pass additional options to `withSentryConfig`:
34+
35+
```javascript {tabTitle: svelte.config.js}
36+
import { withSentryConfig } from "@sentry/svelte";
37+
38+
const config = {
39+
// Your svelte config
40+
compilerOptions: {...},
41+
};
42+
43+
const sentryOptions = {
44+
// Groups all component tracking-related options
45+
// (optional)
46+
componentTracking: {
47+
// Add the components you want to be tracked to this array.
48+
// Specificy `true` to track all components or `false` to disable
49+
// tracking entirely
50+
// (optional, defaults to `true`)
51+
trackComponents: ["Navbar", "PrimaryButton", "LoginForm"],
52+
// To disable component initialization spans, set this to `false`.
53+
// (optional, defaults to `true`)
54+
trackInit: true,
55+
// To disable component update spans, set this to `false`
56+
// (optional, defaults to `true`)
57+
trackUpdates: false,
58+
},
59+
};
60+
61+
export default withSentryConfig(config, sentryOptions);
62+
```
63+
64+
## Component Tracking Spans
4565

4666
This feature adds the following spans to the ongoing transaction:
4767

@@ -55,7 +75,7 @@ This feature adds the following spans to the ongoing transaction:
5575

5676
## Alternative Usage
5777

58-
If you don't want to use our preprocessor to automatically insert the function call at build time, you can call the tracking function manually in every component you would like to see tracked:
78+
If you don't want to use our `withSentryConfig` wrapper to automatically instrument your components at build time, you can call the tracking function manually in every component you would like to see tracked:
5979

6080
```javascript {tabTitle: MyComponent.svelte}
6181
<script>

0 commit comments

Comments
 (0)