tomer-yechiel / pino-sentry-transport

MIT License
28 stars 8 forks source link

Pino Sentry transport

npm version npm downloads bundle JSDocs License

Pino Sentry Transport allows you to send logs from Pino directly to Sentry.

Installation

npm i pino-sentry-transport

Usage

import pino from "pino";

const logger = pino({
    transport: {
        target: "pino-sentry-transport",
        options: {
            sentry: {
                dsn: "https://<key>:<secret>@sentry.io/<project>",
                // additional options for sentry
            },
            withLogRecord: true, // default false - send the entire log record to sentry as a context.(FYI if its more then 8Kb Sentry will throw an error)
            tags: ['level'], // sentry tags to add to the event, uses lodash.get to get the value from the log record
            context: ['hostname'], // sentry context to add to the event, uses lodash.get to get the value from the log record,
            minLevel: 40, // which level to send to sentry
            expectPinoConfig: true, // default false - pass true if pino configured with custom messageKey or errorKey see below
        }
    },
});

Configuration Options

Sentry initialization

Because Pino transport runs in a separate worker thread, Sentry needs to be initialized in the transport.

License

This project is licensed under the MIT License - see the LICENSE file for details.