@flareapp/sveltekit
v2.12.0
Published
SvelteKit integration for flareapp.io
Readme
@flareapp/sveltekit
SvelteKit integration for Flare error tracking and logging. Wraps SvelteKit's client and server
handleError hooks to report unexpected errors with route context. Also provides manual capture helpers and route
tracking for browser-side reports.
Installation
npm install @flareapp/sveltekit @flareapp/jsQuick start
Set up Flare in your SvelteKit hooks:
// src/hooks.client.ts
import { dev } from '$app/environment';
import { flare } from '@flareapp/js';
import { handleErrorWithFlare } from '@flareapp/sveltekit/client';
if (!dev) {
flare.light('YOUR_FLARE_API_KEY');
}
export const handleError = handleErrorWithFlare();// src/hooks.server.ts
import { dev } from '$app/environment';
import { flare } from '@flareapp/js';
import { handleErrorWithFlare } from '@flareapp/sveltekit/server';
if (!dev) {
flare.light('YOUR_FLARE_API_KEY');
}
export const handleError = handleErrorWithFlare();Logging
Beyond errors, the client can send structured logs. Logs are opt-in: enable them with enableLogs, then call any of the
eight syslog levels (debug, info, notice, warning, error, critical, alert, emergency).
import { flare } from '@flareapp/js';
flare.configure({ enableLogs: true });
flare.logger.info('Checkout started', { cartId: cart.id, total: cart.total });Identifying users
import { flare } from '@flareapp/js';
flare.setUser({ id: 123, email: '[email protected]', fullName: 'Jane Doe' });See the JavaScript identifying-users docs for the full field list. Pass null to clear.
Hover-preloaded fetches in traces
SvelteKit's recommended default, data-sveltekit-preload-data="hover", starts a route's load
function, including its fetch, as soon as a visitor hovers a link — before they click it. If they
never click, a trace for the page they were on can still show a fetch for the route they hovered but
never opened. That is a correct record of what the browser did, not a bug, but it can read as wrong
data in a waterfall. Setting data-sveltekit-preload-data to a less eager value (for example "tap")
avoids it.
Documentation
Full documentation on handleErrorWithFlare, captureError, trackRouteContext, lifecycle callbacks, and more is
available at flareapp.io/docs/svelte/general/installation.
Compatibility
- Svelte 5.3+
- SvelteKit 2.12+
License
The MIT License (MIT). Please see License File for more information.
