Skip to content

Commit c536290

Browse files
authored
feat(svelte): Add documentation for component tracking (#5470)
add a page in the Svelte SDK documentation about a new feature in the SDK, component tracking. It includes a brief description of what this feature does and how to use it (two ways).
1 parent 1de623e commit c536290

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Track Svelte Components
3+
---
4+
5+
Sentry's Svelte SDK offers a feature to monitor the performance of your Svelte components: component tracking. Enabling this feature provides you with spans in your transactions that show the initialization and update cycles of your Svelte components. This allows you to get a drilled-down view into how your components are behaving so you can do things like identify slow initializations or frequent updates, which might have an impact on your app's performance.
6+
7+
## Usage
8+
9+
To get started, add the Sentry `componentTrackingPreprocessor` to your `svelte.config.js` file:
10+
11+
```javascript {tabTitle: svelte.config.js}
12+
import * as Sentry from "@sentry/svelte";
13+
14+
const config = {
15+
preprocess: [
16+
Sentry.componentTrackingPreprocessor({
17+
// Add the components you want to be tracked to this array.
18+
// Specificy `true` to track all components or `false` to disable
19+
// tracking entirely
20+
// (defaults to `true`)
21+
trackComponents: ["Navbar", "PrimaryButton", "LoginForm"],
22+
// To disable component initialization spans, set this to `false`.
23+
// (defaults to `true`)
24+
trackInit: true,
25+
// To disable component update spans, set this to `false`
26+
// (defaults to `true`)
27+
trackUpdates: false,
28+
}),
29+
// ...
30+
],
31+
// ...
32+
};
33+
34+
export default config;
35+
```
36+
37+
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.
38+
39+
## Alternative Usage
40+
41+
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:
42+
43+
```javascript {tabTitle: MyComponent.svelte}
44+
<script>
45+
import * as Sentry from "@sentry/svelte";
46+
Sentry.trackComponent({
47+
// To disable component initialization spans, set this to `false`.
48+
// (defaults to `true`)
49+
trackInit: true,
50+
// To disable component update spans, set this to `false`
51+
// (defaults to `true`)
52+
trackUpdates: false,
53+
// Specify a custom name to be shown in the span description
54+
// (defaults to the automatically detected component name)
55+
componentName: string
56+
})
57+
// rest of your code
58+
</script>
59+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Svelte Features
3+
description: "Learn how Sentry's Svelte SDK exposes features for first class integration with Svelte."
4+
excerpt: ""
5+
---
6+
7+
The Sentry Svelte SDK offers Svelte-specific features for first class integration with the framework.
8+
9+
- **[Component Tracking](./componenttracking/)**
10+
11+
If you're using Performance monitoring, you can track the individual components of your Svelte application.

0 commit comments

Comments
 (0)