React
Altix ErrorTrack unterstützt das Sentry-Protokoll, sodass Sie das offizielle @sentry/react-SDK verwenden. Die folgenden Code-Snippets nutzen einen Platzhalter-DSN; auf der Einrichtungsseite Ihres Projekts finden Sie die echten Werte.
SDK installieren
Fügen Sie
@sentry/reacthinzu, das offizielle Sentry-SDK. Es funktioniert unverändert mit Altix ErrorTrack.bash
npm install @sentry/react --saveKonfigurieren
Initialisieren Sie das SDK so früh wie möglich in Ihrer App mit Ihrer DSN.
src/instrument.js
import * as Sentry from "@sentry/react"; 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", });src/main.jsx
// Import instrument.js before anything else. import "./instrument"; import App from "./App"; import { createRoot } from "react-dom/client"; import * as Sentry from "@sentry/react"; const root = createRoot(document.getElementById("app"), { onUncaughtError: Sentry.reactErrorHandler(), onCaughtError: Sentry.reactErrorHandler(), onRecoverableError: Sentry.reactErrorHandler(), }); root.render(<App />);Source Maps hochladen
Damit Stacktraces Ihren Originalcode statt des minifizierten Codes anzeigen. Erstellen Sie unter Einstellungen → Auth-Tokens ein Auth-Token mit dem Scope
project:releasesund bewahren Sie es in Ihren CI-Secrets auf – niemals im Repository.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 ./distÜberprüfen
Lösen Sie absichtlich einen Fehler aus. Er erscheint innerhalb weniger Sekunden in Ihrem Issue-Stream.
jsx
<button onClick={() => { throw new Error("My first ErrorTrack error"); }}> Break the world </button>
Erstellen Sie ein Projekt, und auf der Einrichtungsseite wird automatisch Ihre echte DSN eingetragen.