Express

Altix ErrorTrack supporta il protocollo Sentry, quindi puoi utilizzare l'SDK ufficiale di @sentry/node. I frammenti di codice qui sotto mostrano un DSN di esempio; la pagina di configurazione del tuo progetto li mostrerà con quello reale.

  1. Installa l'SDK

    Aggiungi @sentry/node, l'SDK ufficiale di Sentry. Funziona senza modifiche con Altix ErrorTrack.

    bash

    npm install @sentry/node --save
  2. Configuralo

    Inizializza l'SDK il prima possibile nella tua app, inserendo il tuo 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);
  3. Carica le source map

    In questo modo gli stack trace mostrano il tuo codice originale invece di quello minificato. Crea un token di autenticazione con ambito project:releases in Impostazioni → Token di autenticazione e salvalo nei secret della tua CI, mai nel 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

    Guida alle source map

  4. Verifica

    Genera un errore di proposito. Apparirà nel tuo elenco delle segnalazioni entro pochi secondi.

    javascript

    app.get("/debug-errortrack", () => {
      throw new Error("My first ErrorTrack error");
    });

Crea un progetto e la pagina di configurazione genererà automaticamente il tuo DSN reale.