Wondering what’s next for npm?Check out our public roadmap! »

    sentry-error-transport

    1.0.6 • Public • Published

    Sentry Error Transport

    A tiny Sentry transport for Winston.

    Features

    Installation

    npm install sentry-error-transport
    

    Usage

    Configure Winston

    You can create a new transport object for Winston by initializing the SentryTransport class. It accepts an object containing sentry and transport configuration. The level property passed in will dictate which log level is passed on to Sentry.

    "use strict";
    const winston = require("winston");
    const SentryTransport = require("sentry-error-transport");
     
    const logger = winston.createLogger({
      level: "info",
      format: winston.format.simple()
      transports: [
        new winston.transports.Console(),
        new SentryTransport({ level: "error", sentry: { dns: "{SENTRY_URL}" } })
      ]
    });

    Format

    const config = {
      sentry: {
        dns: "{SENTRY_URL}",
        /* any other sentry config goes here */
      },
      level: "error",
      /* any other winston-transport config goes here */
    }
     
    const transport = new SentryTransport(config)

    Use logger

    // these are only logged in console
    logger.info("Hello");
    logger.warn("Something happened", { user: req.user })
     
    // when logging errors, send an error object as the first param
    // this gets sent to the Sentry transport
    logger.error(new Error("Something went wrong"), {
      user: req.user,
      extraMeta: "data"
    })
     
    //  ============= or =============
     
    try {
      // something throws an error...
    }
    catch(err) {
      // this gets sent to the Sentry transport
      logger.error(err, { user: req.user, stack: err.stack })
    }

    Access Sentry

    The Sentry object can be accessed at SentryTransport.Sentry property

    const SentryTransport = require("sentry-error-transport");
    const { Sentry } = SentryTransport;

    Keywords

    none

    Install

    npm i sentry-error-transport

    DownloadsWeekly Downloads

    3

    Version

    1.0.6

    License

    ISC

    Unpacked Size

    3.08 kB

    Total Files

    3

    Last publish

    Collaborators

    • avatar