Angular
Altix ErrorTrack utilise le protocole Sentry : vous pouvez donc vous servir du SDK officiel @sentry/angular. Les extraits ci-dessous utilisent un DSN d'exemple ; la page de configuration de votre projet les affiche avec votre véritable DSN.
Installer le SDK
Ajoutez
@sentry/angular, le SDK Sentry officiel. Il fonctionne sans aucune modification avec Altix ErrorTrack.bash
npm install @sentry/angular --saveLe configurer
Initialisez le SDK le plus tôt possible dans votre application, à l'aide de votre DSN.
src/main.ts
import * as Sentry from "@sentry/angular"; Sentry.init({ dsn: "https://<public-key>@errortrack.altixcode.com/<project-id>", release: "my-app@1.0.0", integrations: [ Sentry.browserTracingIntegration(), Sentry.replayIntegration(), ], // Capture 100% of traces while you try it; lower this in production. tracesSampleRate: 1.0, // Record 10% of sessions, and every session that has an error. replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0, // Optional: send events through your own server to get past ad blockers (see /docs/tunnel) // tunnel: "/monitoring", }); bootstrapApplication(AppComponent, appConfig);src/app/app.config.ts
import { ApplicationConfig, ErrorHandler, inject, provideAppInitializer } from "@angular/core"; import { Router } from "@angular/router"; import * as Sentry from "@sentry/angular"; export const appConfig: ApplicationConfig = { providers: [ { provide: ErrorHandler, useValue: Sentry.createErrorHandler() }, { provide: Sentry.TraceService, deps: [Router] }, provideAppInitializer(() => { inject(Sentry.TraceService); }), ], };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:releasessous Paramètres → Jetons d'authentification et conservez-le dans les secrets de votre CI, jamais dans le dépôt.bash
# After your production build, in CI: 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> npx @sentry/cli sourcemaps inject ./dist npx @sentry/cli sourcemaps upload --release=my-app@1.0.0 ./distVérifier
Déclenchez volontairement une erreur. Elle apparaîtra dans votre flux de problèmes en quelques secondes.
html
<button (click)="throwTestError()">Break the world</button> <!-- throwTestError(): void { throw new Error("My first ErrorTrack error"); } -->
Créez un projet et sa page de configuration préremplira votre véritable DSN.