npm.io
1.6.0 • Published 7 months ago

pino-sentry-transport

Licence
MIT
Version
1.6.0
Deps
2
Size
14 kB
Vulns
0
Weekly
0
Stars
41

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
            },
            // default false - send the entire log record to Sentry as a context.
            // FYI: if it's more than 8Kb, Sentry will throw an error
            withLogRecord: true,
            // sentry tags to add to the event, uses `lodash.get` to get the value from the log record
            tags: ['level'],
            // sentry context to add to the event, uses `lodash.get` to get the value from the log record
            context: ['hostname'],
            // which level to send to Sentry
            minLevel: 40,
            // default false - pass true if pino is configured with custom messageKey or errorKey, see below
            expectPinoConfig: true,
        }
    },
});
Configuration Options
  • withLogRecord: When set to true, sends the entire log record as context to Sentry. Be cautious of log records larger than 8KB, as Sentry will throw an error.
  • tags: An array specifying which fields from the log record should be added as tags in Sentry. Uses lodash.get to extract values.
  • context: An array specifying which fields from the log record should be added as context in Sentry. Also uses lodash.get for value extraction.
  • minLevel: The minimum log level required for a message to be sent to Sentry. Log levels follow Pino's conventions (e.g., 50 for 'error').
  • expectPinoConfig: If set to true, allows the transport to work with custom messageKey or errorKey settings in Pino.
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.