Skip to content

Commit 9098555

Browse files
Lms24imatwawana
andauthored
feat: Add Svelte SDK docs (#5413)
Add official documentation to the new @sentry/svelte JS SDK which is currently in aplha. It includes - A disclaimer that this SDK is in alpha and subject to breaking changes - Instructions for installing and using the SDK in Svelte projects - Instruction for generating and uploading Sourcemaps in Svelte projects Co-authored-by: Isabel <[email protected]>
1 parent bde333d commit 9098555

File tree

11 files changed

+158
-0
lines changed

11 files changed

+158
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
You can pass an `Error` object to `captureException()` to have it captured as an event. It's also possible to pass non-`Error` objects and strings, but be aware that the resulting events in Sentry may be missing a stack trace.
2+
3+
```typescript
4+
import * as Sentry from "@sentry/svelte";
5+
6+
try {
7+
aFunctionThatMightFail();
8+
} catch (err) {
9+
Sentry.captureException(err);
10+
}
11+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
To use the SDK, initialize it in your Svelte entry point before bootstrapping your app. In a typical Svelte project, that is your `main.js` or `main.ts` file.
2+
3+
```typescript {filename: main.ts}
4+
import "./app.css";
5+
import App from "./App.svelte";
6+
7+
import * as Sentry from "@sentry/svelte";
8+
import { BrowserTracing } from "@sentry/tracing";
9+
10+
// Initialize the Sentry SDK here
11+
Sentry.init({
12+
dsn: "___PUBLIC_DSN___",
13+
integrations: [new BrowserTracing()],
14+
15+
// Set tracesSampleRate to 1.0 to capture 100%
16+
// of transactions for performance monitoring.
17+
// We recommend adjusting this value in production
18+
tracesSampleRate: 1.0,
19+
});
20+
21+
const app = new App({
22+
target: document.getElementById("app"),
23+
});
24+
25+
export default app;
26+
```
27+
28+
```javascript {filename: main.js}
29+
import "./app.css";
30+
import App from "./App.svelte";
31+
32+
import * as Sentry from "@sentry/svelte";
33+
import { BrowserTracing } from "@sentry/tracing";
34+
35+
// Initialize the Sentry SDK here
36+
Sentry.init({
37+
dsn: "___PUBLIC_DSN___",
38+
integrations: [new BrowserTracing()],
39+
40+
// Set tracesSampleRate to 1.0 to capture 100%
41+
// of transactions for performance monitoring.
42+
// We recommend adjusting this value in production
43+
tracesSampleRate: 1.0,
44+
});
45+
46+
const app = new App({
47+
target: document.getElementById("app"),
48+
});
49+
50+
export default app;
51+
```
52+
53+
Once you've done this, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client. You can also [manually capture errors](/platforms/javascript/guides/svelte/usage).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```bash {tabTitle:npm}
2+
npm install --save @sentry/svelte @sentry/tracing
3+
```
4+
5+
```bash {tabTitle:yarn}
6+
yarn add @sentry/svelte @sentry/tracing
7+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Note>
2+
3+
Sentry's Svelte SDK enables automatic reporting of errors and exceptions, as well as performance monitoring for your client-side Svelte apps.
4+
5+
</Note>
6+
7+
<Alert level="info" title="Important">
8+
9+
This SDK is considered **experimental and in alpha state**. It may experience breaking changes. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have any feedback or concerns. The SDK currently only supports [Svelte](https://svelte.dev/) and is not yet compatible with with [SvelteKit](https://kit.svelte.dev/).
10+
11+
</Alert>
12+
13+
Sentry's Svelte SDK was introduced with version `7.10.0`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```jsx {tabTitle:Svelte} {filename:SomeCmponent.svelte}
2+
<button
3+
type="button"
4+
on:click={() => {
5+
throw new Error("Sentry Frontend Error");
6+
}}
7+
>
8+
Throw error
9+
</button>
10+
```
11+
12+
This snippet adds a button that throws an error in a Svelte component.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
To generate source maps with your Svelte project, you need to set the source map [compiler options](https://svelte.dev/docs#compile-time-svelte-compile) in your Svelte config:
2+
3+
```JavaScript {filename:svelte.config.js}
4+
import sveltePreprocess from "svelte-preprocess";
5+
6+
const config = {
7+
compilerOptions: {
8+
enableSourcemap: true,
9+
},
10+
preprocess: sveltePreprocess({
11+
sourceMap: true,
12+
}),
13+
};
14+
15+
export default config;
16+
```
17+
18+
Additionally, you need to enable source map output in your bundler. The following example shows how to do this for Vite:
19+
20+
```JavaScript {filename:vite.config.js}
21+
import { defineConfig } from "vite";
22+
import { svelte } from "@sveltejs/vite-plugin-svelte";
23+
24+
export default defineConfig({
25+
plugins: [svelte()],
26+
build: {
27+
sourcemap: true,
28+
},
29+
});
30+
```
31+
32+
If you're using bundlers other than Vite, check out our general guide on how to [generate source maps](../../../../sourcemaps/generating) with them, or refer to their documentation.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Integrate your Svelte project's source maps with Sentry using these steps:
2+
3+
### 1: Generate Source Maps
4+
5+
The Svelte compiler and your bundler (for example, Vite) need to be configured to output source maps. Learn more about [how to generate source maps with Svelte](./generating/).
6+
7+
### 2: Provide Source Maps to Sentry
8+
9+
Source maps can be uploaded to Sentry by creating a release. Learn more about [how to upload source maps](./uploading/).
10+
11+
<Note>
12+
13+
By default, if Sentry can't find the uploaded files it needs, it will attempt to download them from the URLs in the stack trace. To disable this, turn off "Enable JavaScript source fetching" in either your organization's "Security & Privacy" settings or your project's general settings.
14+
15+
</Note>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
To upload your Svelte project's source maps to Sentry, you currently have two options:
2+
3+
- Upload source maps manually using [Sentry-CLI](./cli/). Take a look at this [bash script](https://github.com/getsentry/sentry-javascript/tree/master/packages/svelte#sourcemaps-and-releases) as an example of how to configure the CLI for a typical Svelte project.
4+
- Use the [unofficial Sentry Vite plugin](https://github.com/ikenfin/vite-plugin-sentry) to set releases and upload source maps. **Please note that this plugin is not maintained by Sentry and we do not offer support for it.**
5+
6+
For other bundlers or more advanced configurations, take a look at the following guides and options for uploading sourcemaps:

src/includes/troubleshooting/older-browser-support/javascript.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Though the above example is Webpack-specific, similar changes can be made to con
4141
"javascript.nextjs",
4242
"javascript.react",
4343
"javascript.remix",
44+
"javascript.svelte",
4445
"javascript.vue",
4546
"javascript.wasm",
4647
]}>

src/platforms/javascript/common/install/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ notSupported:
1414
- javascript.vue
1515
- javascript.wasm
1616
- javascript.remix
17+
- javascript.svelte
1718
---
1819

1920
<PageGrid />

0 commit comments

Comments
 (0)