Express
Altix ErrorTrack unterstützt das Sentry-Protokoll, sodass Sie das offizielle @sentry/node-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/nodehinzu, das offizielle Sentry-SDK. Es funktioniert unverändert mit Altix ErrorTrack.bash
npm install @sentry/node --saveKonfigurieren
Initialisieren Sie das SDK so früh wie möglich in Ihrer App mit Ihrer DSN.
instrument.js
const Sentry = require("@sentry/node"); Sentry.init({ dsn: "https://<public-key>@errortrack.altixcode.com/<project-id>", release: "my-app@1.0.0", // Capture 100% of traces while you try it; lower this in production. tracesSampleRate: 1.0, });app.js
// Run with: node --import ./instrument.js app.js const Sentry = require("@sentry/node"); const express = require("express"); const app = express(); app.get("/", (req, res) => res.send("Hello world!")); // After all controllers, before any other error middleware. Sentry.setupExpressErrorHandler(app); app.listen(3000);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.
javascript
app.get("/debug-errortrack", () => { throw new Error("My first ErrorTrack error"); });
Erstellen Sie ein Projekt, und auf der Einrichtungsseite wird automatisch Ihre echte DSN eingetragen.