
Sentry Svelte Sdk
Wire Sentry into Svelte or SvelteKit so client and server errors, hooks, and request pipelines are captured without custom plumbing.
Install
npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-svelte-sdkWhat is this skill?
- Baseline capture from a single `Sentry.init()` via globalHandlers and browserApiErrors on the client
- SvelteKit server pipeline: `handleErrorWithSentry()` in `hooks.server.ts` plus `sentryHandle()` for request instrumentat
- Client navigation errors via `handleErrorWithSentry()` in `hooks.client.ts` with optional custom handler chaining
- Minimum SDK versions: `@sentry/sveltekit` and `@sentry/svelte` ≥ 7.0.0+
- Layer table covering client vs server mechanisms and when each integration fires
Adoption & trust: 987 installs on skills.sh; 197 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Error monitoring is a production responsibility: the skill documents how events are captured after the app is live or in staging, which maps to Operate. Sentry is observability and alert-oriented instrumentation, not feature build or incident triage alone—canonical shelf is monitoring under Operate.
Common Questions / FAQ
Is Sentry Svelte Sdk safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Sentry Svelte Sdk
# Error Monitoring — Sentry Svelte/SvelteKit SDK > Minimum SDK: `@sentry/sveltekit` ≥7.0.0+ / `@sentry/svelte` ≥7.0.0+ --- ## How Automatic Capture Works | Layer | Mechanism | Fires when... | |-------|-----------|---------------| | **Client (both)** | `globalHandlersIntegration` | `window.onerror`, unhandled `Promise` rejections | | **Client (both)** | `browserApiErrorsIntegration` | Errors thrown in `setTimeout`, `setInterval`, `requestAnimationFrame` | | **Server (SvelteKit)** | `handleErrorWithSentry()` in `hooks.server.ts` | Any unhandled error in a server hook, load function, or route handler | | **Server (SvelteKit)** | `sentryHandle()` | Instruments incoming requests; captures errors from the request pipeline | | **Client (SvelteKit)** | `handleErrorWithSentry()` in `hooks.client.ts` | Any unhandled navigation or client-side error SvelteKit surfaces | No configuration beyond the `Sentry.init()` call is required for baseline error capture. --- ## SvelteKit Error Hooks ### `hooks.client.ts` ```typescript import * as Sentry from "@sentry/sveltekit"; Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN, sendDefaultPii: true }); // Sentry captures first; your handler runs after const myErrorHandler = ({ error, event }: { error: unknown; event: unknown }) => { console.error("Client error:", error); }; export const handleError = Sentry.handleErrorWithSentry(myErrorHandler); // Works with no argument too: // export const handleError = Sentry.handleErrorWithSentry(); ``` ### `hooks.server.ts` ```typescript import * as Sentry from "@sentry/sveltekit"; import { sequence } from "@sveltejs/kit/hooks"; // Sentry.init() is in instrumentation.server.ts (modern) or here (legacy) const myErrorHandler = ({ error, event }: { error: unknown; event: unknown }) => { console.error("Server error:", error); }; export const handleError = Sentry.handleErrorWithSentry(myErrorHandler); // sentryHandle() instruments requests and creates root spans export const handle = Sentry.sentryHandle(); // Composing multiple handles: // export const handle = sequence(Sentry.sentryHandle(), authHandle, logHandle); ``` ### `handleErrorWithSentry()` callback signature ```typescript export const handleError = Sentry.handleErrorWithSentry( (input: { error: unknown; event: RequestEvent | NavigationEvent; status?: number; message?: string; }) => { // Your logic runs AFTER Sentry has already captured the error } ); ``` --- ## Manual Error Capture ```typescript import * as Sentry from "@sentry/sveltekit"; // or "@sentry/svelte" // Capture an Error object try { await riskyOperation(); } catch (err) { Sentry.captureException(err); } // Capture with extra context try { await riskyOperation(); } catch (err) { Sentry.captureException(err, { tags: { feature: "checkout", region: "eu" }, extra: { cartId: "abc-123", itemCount: 3 }, level: "error", // "fatal" | "error" | "warning" | "info" | "debug" }); } // Plain message (not tied to an exception) Sentry.captureMessage("User exceeded rate limit", "warning"); // Isolated scope — doesn't pollute global state Sentry.withScope((scope) => { scope.setTag("component", "PaymentForm"); scope.setUser({ id: "42", email: "user@example.com" }); Sentry.captureException(new Error("Payment failed")); }); ``` --- ## Context Enrichment ### User Context ```typescript // Set globally — persists until cleared Sentry.setUser({ id: "user-123", email: "jane@example.com", username: "jdoe", ip_address: "{{ auto }}", // auto-infer from request plan: "enterprise", // custom fields accepted }); // Clear on logout Sentry.setUser(null); ``` ### Tags (searchable, indexed) ```typescript Sentry.setTag("release.channel", "beta"); Sentry.setTags({ "feature.flag": "new-checkout", region: "us-east-1", version: "2.1.0", }); ``` Key constraints: ≤32 chars, alphanumeric + `_`, `.`, `:`, `-`. Value: ≤200 chars, no newlines. ### Context Objects (structur