Skip to main content
Backend tracing allows Sonarly to link backend errors and traces with frontend sessions, giving you full visibility into issues across your stack.

Step 1: Install the Sentry SDK

npm install @sentry/node

Step 2: Initialize Sentry

Add this at the very top of your entry file, before any other imports:
const Sentry = require("@sentry/node");

Sentry.init({
  dsn: "https://YOUR_PROJECT_KEY@sonarly.dev/YOUR_PROJECT_ID",
  tracesSampleRate: 1.0,
  environment: process.env.NODE_ENV || "development",
});

// Session linking middleware (add before routes)
app.use((req, res, next) => {
  const sessionId = req.headers['x-sonarly-session-id'];
  if (sessionId) Sentry.setTag('sonarly.session_id', sessionId);
  next();
});

Step 3: Enable CORS for Session Header

Make sure your backend allows the x-sonarly-session-id header:
const cors = require('cors');

app.use(cors({
  exposedHeaders: ['x-sonarly-session-id'],
  allowedHeaders: ['x-sonarly-session-id']
}));

DSN Format

Your DSN can be found in the Sonarly dashboard. It follows this format:
https://YOUR_PROJECT_KEY@sonarly.dev/YOUR_PROJECT_ID

Verify

After deploying, check that:
  1. Backend errors appear in your Sonarly dashboard
  2. Errors are linked to frontend sessions (you’ll see the session replay)
  3. Traces show the full request flow

View AI Alerts

Get notified about critical issues automatically