SvelteKit

Altix ErrorTrack utilise le protocole Sentry : vous pouvez donc vous servir du SDK officiel @sentry/sveltekit. Les extraits ci-dessous utilisent un DSN d'exemple ; la page de configuration de votre projet les affiche avec votre véritable DSN.

  1. Installer le SDK

    Ajoutez @sentry/sveltekit, le SDK Sentry officiel. Il fonctionne sans aucune modification avec Altix ErrorTrack.

    bash

    npm install @sentry/sveltekit --save
  2. Le configurer

    Initialisez le SDK le plus tôt possible dans votre application, à l'aide de votre DSN.

    src/hooks.client.js

    import * as Sentry from "@sentry/sveltekit";
    
    Sentry.init({
      dsn: "https://<public-key>@errortrack.altixcode.com/<project-id>",
      integrations: [Sentry.replayIntegration()],
      tracesSampleRate: 1.0,
      replaysSessionSampleRate: 0.1,
      replaysOnErrorSampleRate: 1.0,
      // Optional: send events through your own server to get past ad blockers (see /docs/tunnel)
      // tunnel: "/monitoring",
    });
    
    export const handleError = Sentry.handleErrorWithSentry();

    src/instrumentation.server.js

    import * as Sentry from "@sentry/sveltekit";
    
    Sentry.init({
      dsn: "https://<public-key>@errortrack.altixcode.com/<project-id>",
      tracesSampleRate: 1.0,
    });

    src/hooks.server.js

    import * as Sentry from "@sentry/sveltekit";
    
    export const handle = Sentry.sentryHandle();
    export const handleError = Sentry.handleErrorWithSentry();

    vite.config.js

    import { sveltekit } from "@sveltejs/kit/vite";
    import { sentrySvelteKit } from "@sentry/sveltekit/vite";
    import { defineConfig } from "vite";
    
    export default defineConfig({
      // sentrySvelteKit must come before sveltekit.
      plugins: [sentrySvelteKit(), sveltekit()],
    });
  3. Téléverser les source maps

    Pour que les stack traces affichent votre code d'origine plutôt que le code minifié. Créez un jeton d'authentification avec la portée project:releases sous Paramètres → Jetons d'authentification et conservez-le dans les secrets de votre CI, jamais dans le dépôt.

    bash

    # Set in the build environment; the SDK's build plugin uploads source maps with them.
    export SENTRY_URL=https://errortrack.altixcode.com
    export SENTRY_ORG=<org-slug>
    export SENTRY_PROJECT=<project-slug>
    export SENTRY_AUTH_TOKEN=<an auth token from Settings → Auth Tokens>

    Guide des source maps

  4. Vérifier

    Déclenchez volontairement une erreur. Elle apparaîtra dans votre flux de problèmes en quelques secondes.

    html

    <button on:click={() => { throw new Error("My first ErrorTrack error"); }}>Break the world</button>

Créez un projet et sa page de configuration préremplira votre véritable DSN.