diff --git a/README.md b/README.md index b7b0098..6647237 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,9 @@ import { SentryTransport } from 'winston-sentry-javascript-node'; const logger = winston.createLogger({ transports: [ new SentryTransport({ - dsn: 'MY_SENTRY_DSN', + sentry{ + dsn: 'MY_SENTRY_DSN', + }, }), ], }); @@ -62,7 +64,9 @@ Catch and send `uncaughtException` to the Sentry. const logger = winston.createLogger({ transports: [ new SentryTransport({ - dsn: 'MY_SENTRY_DSN', + sentry{ + dsn: 'MY_SENTRY_DSN', + }, handleExceptions: true, }), ], @@ -73,12 +77,37 @@ const logger = winston.createLogger({ const logger = winston.createLogger({ exceptionHandlers: [ new SentryTransport({ - dsn: 'MY_SENTRY_DSN', + sentry: { + dsn: 'MY_SENTRY_DSN', + } }), ] }); ``` +## Options + +```javascript +new SentryTransport(opts) +``` + +* opts: TransportStreamOptions + +```javascript +interface TransportStreamOptions { + format?: logform.Format; + level?: string; + silent?: boolean; + handleExceptions?: boolean; + + log?(info: any, next: () => void): any; + logv?(info: any, next: () => void): any; + close?(): void; +} +``` + +* opts.sentry: Please see [Sentry client options](https://docs.sentry.io/error-reporting/configuration/?platform=javascript). + ## Default Extra for Error Object By default, if you provide an Error Object to logger, this package will set the following extra: diff --git a/example/example.ts b/example/example.ts index 7c2e963..24d5f95 100644 --- a/example/example.ts +++ b/example/example.ts @@ -5,7 +5,9 @@ import { SentryTransport } from '../src/index'; const logger = winston.createLogger({ transports: [ new SentryTransport({ - dsn: process.env.SENTRY_DSN, + sentry: { + dsn: process.env.SENTRY_DSN, + }, level: 'error', handleExceptions: true, }) diff --git a/package.json b/package.json index 0c852f4..4a197ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "winston-sentry-javascript-node", - "version": "0.1.3", + "version": "0.2.0", "description": "Sentry transport for the winson logger that using official Sentry SDK for javascript instead of the old Raven.", "main": "lib/index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 73afa23..6e62c22 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,10 +2,6 @@ import { LogEntry } from 'winston'; import Transport, { TransportStreamOptions } from 'winston-transport'; import * as Sentry from '@sentry/node'; -export interface SentryOption { - dsn: string; -} - export interface Extra { extra?: { [key: string]: any; @@ -22,14 +18,17 @@ export interface UserInfo { user?: Sentry.User } +export interface SentryOptions { + sentry: Sentry.NodeOptions; +} + export type Log = LogEntry & Extra & Tag & UserInfo; export class SentryTransport extends Transport { - public constructor(opts: TransportStreamOptions & SentryOption) { - super(opts); - Sentry.init({ - dsn: opts.dsn, - }); + public constructor(opts: TransportStreamOptions & SentryOptions) { + const { sentry, ...rest } = opts; + super(rest); + Sentry.init(sentry); } public log(info: Log, next: () => void): void {