pino-sentry
raw JSON → 0.15.0 verified Sat Apr 25 auth: no javascript
A transport (stream) for the pino logger that sends logs to Sentry via @sentry/node. Current stable version 0.15.0 supports pino v7+ and Sentry SDK v7. It works as a CLI tool or programmatic stream, exposing both createWriteStream and the Sentry instance directly. Release cadence is sporadic. Key differentiators: lightweight, simple integration, and exposes the underlying Sentry instance for advanced usage. Requires Node >=10 and @sentry/node as a peer dependency. Self-hosted Sentry users must be on 20.6.0+ with Sentry SDK v7.
Common errors
error Cannot find module '@sentry/node' ↓
cause Missing peer dependency @sentry/node.
fix
Install it: npm install @sentry/node
error Sentry SDK version mismatch: expected v7 but got v6 ↓
cause Installed @sentry/node is v6, pino-sentry v0.15 requires v7.
fix
Upgrade @sentry/node to version ^7.0.0
error TypeError: createWriteStream is not a function ↓
cause Incorrect import: using default import instead of named import.
fix
Use import { createWriteStream } from 'pino-sentry'
error Error: No DSN provided. Set SENTRY_DSN environment variable or pass --dsn ↓
cause DSN is missing when using the CLI or creating the stream without setting 'dsn' option.
fix
Set SENTRY_DSN env var or pass dsn option to createWriteStream.
Warnings
gotcha The Sentry SDK v7 requires self-hosted Sentry 20.6.0+. Older on-premise versions will fail. ↓
fix Upgrade sentry self-hosted to 20.6.0+ or use pino-sentry versions prior to 0.15.0 with Sentry SDK v6.
gotcha CLI usage (pipe to pino-sentry) must call with --dsn or set SENTRY_DSN environment variable, otherwise it throws error. ↓
fix Provide DSN via --dsn flag or SENTRY_DSN env var.
deprecated The 'sampleRate' option as a percentage (0.0-1.0) is deprecated; use the 'tracesSampleRate' option directly on Sentry.init if needed. ↓
fix Replace sampleRate with 'tracesSampleRate' in Sentry.init (outside pino-sentry options).
breaking Breaking change in v0.15.0: Removed support for @sentry/node v6. Only v7 is supported. ↓
fix Update @sentry/node to v7.x and ensure self-hosted Sentry >=20.6.0.
Install
npm install pino-sentry yarn add pino-sentry pnpm add pino-sentry Imports
- createWriteStream wrong
const createWriteStream = require('pino-sentry').createWriteStreamcorrectimport { createWriteStream } from 'pino-sentry' - Sentry wrong
const Sentry = require('pino-sentry').defaultcorrectimport { Sentry } from 'pino-sentry' - Severity wrong
const Severity = require('pino-sentry')correctimport { Severity } from 'pino-sentry' - createWriteStream via CJS require wrong
const createWriteStream = require('pino-sentry').defaultcorrectconst { createWriteStream } = require('pino-sentry')
Quickstart
import { createWriteStream } from 'pino-sentry';
import pino from 'pino';
const stream = createWriteStream({
dsn: process.env.SENTRY_DSN ?? '',
environment: process.env.NODE_ENV ?? 'production',
level: 'info',
maxBreadcrumbs: 50,
});
const logger = pino({ level: 'info' }, stream);
logger.info({ msg: 'Hello from pino-sentry' });
logger.error({ err: new Error('Test error') }, 'Error occurred');