1.0.6 • Published 4 years ago

sentry-error-transport v1.0.6

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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;
1.0.6

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago