Sentry · Template docs
Sending data

Node

Send errors, structured logs and linked spans from Node.

Prepare the application

Use the template's examples/node/ directory. Set SENTRY_DSN in the runtime environment using the private DSN. The pinned SDK version is 10.75.3, from package.json.

Run in the same Railway environment as the template, or use a locally reachable installation. A laptop cannot reach the private Railway listener through railway run.

Run the example

From the template repository root:

cd examples/node
npm install --ignore-scripts --no-package-lock
npm start

Example source

This is the included app.mjs, reproduced without changes.

import * as Sentry from "@sentry/node";
if (!process.env.SENTRY_DSN) throw new Error("Set SENTRY_DSN");
Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 1.0,
  enableLogs: true, sendDefaultPii: false });
Sentry.startSpan({ name: "railway-example", op: "task", forceTransaction: true }, () => {
  Sentry.startSpan({ name: "child span", op: "work" }, () => {
    Sentry.logger.info("Railway structured log from Node");
    Sentry.captureException(new Error("Railway error example from Node"));
  });
});
if (!(await Sentry.close(30000))) throw new Error("Telemetry flush timed out");
console.log("SDK flush completed; verify Issues, Logs, and Traces");

Verify in Sentry

Open Issues, Logs and Traces for the same project and environment. Look for Railway error example from Node, Railway structured log from Node and railway-example. Confirm the child span belongs to its parent.

The sample uses full trace sampling for verification. Choose sampling for your workload. A completed flush does not prove server indexing. Use Troubleshooting if any telemetry type is missing.

Unofficial community template, not affiliated with or endorsed by Sentry.

Sentry is Fair Source (FSL-1.1-Apache-2.0), source-available software. Copyright Functional Software, Inc. dba Sentry.

For monitoring your own applications, not for offering Sentry as a hosted service to third parties.

Licensing · Upstream LICENSE.md

On this page