pino-sentry
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -1,1 +0,1 @@ | ||
export { createWriteStream, createWriteStreamAsync } from './transport'; | ||
export { createWriteStream, createWriteStreamAsync, SentryInstance as Sentry } from './transport'; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "createWriteStreamAsync", { enumerable: true, get: function () { return transport_1.createWriteStreamAsync; } }); | ||
Object.defineProperty(exports, "Sentry", { enumerable: true, get: function () { return transport_1.SentryInstance; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
declare type ValueOf<T> = T extends any[] ? T[number] : T[keyof T]; | ||
export declare const SentryInstance: typeof Sentry; | ||
declare const SEVERITIES_MAP: { | ||
@@ -36,2 +37,4 @@ readonly 10: Sentry.Severity.Debug; | ||
maxValueLength?: number; | ||
sentryExceptionLevels?: Sentry.Severity[]; | ||
decorateScope?: (data: Record<string, unknown>, _scope: Sentry.Scope) => void; | ||
} | ||
@@ -44,2 +47,4 @@ export declare class PinoSentryTransport { | ||
maxValueLength: number; | ||
sentryExceptionLevels: Sentry.Severity[]; | ||
decorateScope: (_data: Record<string, unknown>, _scope: Sentry.Scope) => void; | ||
constructor(options?: PinoSentryOptions); | ||
@@ -46,0 +51,0 @@ getLogSeverity(level: keyof typeof SEVERITIES_MAP): Sentry.Severity; |
@@ -25,3 +25,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createWriteStreamAsync = exports.createWriteStream = exports.PinoSentryTransport = void 0; | ||
exports.createWriteStreamAsync = exports.createWriteStream = exports.PinoSentryTransport = exports.SentryInstance = void 0; | ||
const split2_1 = __importDefault(require("split2")); | ||
@@ -31,2 +31,3 @@ const pumpify_1 = __importDefault(require("pumpify")); | ||
const Sentry = __importStar(require("@sentry/node")); | ||
exports.SentryInstance = Sentry; | ||
class ExtendedError extends Error { | ||
@@ -65,2 +66,5 @@ constructor(info) { | ||
}; | ||
function get(data, path) { | ||
return path.split('.').reduce((acc, part) => acc && acc[part], data); | ||
} | ||
class PinoSentryTransport { | ||
@@ -74,2 +78,4 @@ constructor(options) { | ||
this.maxValueLength = 250; | ||
this.sentryExceptionLevels = [Sentry.Severity.Fatal, Sentry.Severity.Error]; | ||
this.decorateScope = (_data, _scope) => { }; | ||
Sentry.init(this.validateOptions(options || {})); | ||
@@ -112,5 +118,6 @@ } | ||
}); | ||
const message = chunk[this.messageAttributeKey]; | ||
const stack = chunk[this.stackAttributeKey] || ''; | ||
const message = get(chunk, this.messageAttributeKey); | ||
const stack = get(chunk, this.stackAttributeKey) || ''; | ||
const scope = new Sentry.Scope(); | ||
this.decorateScope(chunk, scope); | ||
scope.setLevel(severity); | ||
@@ -143,3 +150,3 @@ if (this.isObject(tags)) { | ||
validateOptions(options) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e, _f; | ||
const dsn = options.dsn || process.env.SENTRY_DSN; | ||
@@ -161,2 +168,4 @@ if (!dsn) { | ||
this.maxValueLength = (_d = options.maxValueLength) !== null && _d !== void 0 ? _d : this.maxValueLength; | ||
this.sentryExceptionLevels = (_e = options.sentryExceptionLevels) !== null && _e !== void 0 ? _e : this.sentryExceptionLevels; | ||
this.decorateScope = (_f = options.decorateScope) !== null && _f !== void 0 ? _f : this.decorateScope; | ||
return { | ||
@@ -179,3 +188,3 @@ dsn, | ||
isSentryException(level) { | ||
return level === Sentry.Severity.Fatal || level === Sentry.Severity.Error; | ||
return this.sentryExceptionLevels.includes(level); | ||
} | ||
@@ -182,0 +191,0 @@ shouldLog(severity) { |
{ | ||
"name": "pino-sentry", | ||
"description": "@sentry/node transport for pino logger", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"author": "Andrew Avdeev <andrewww.avdeev@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -0,3 +1,3 @@ | ||
# pino-sentry | ||
# pino-sentry | ||
[![CircleCI](https://circleci.com/gh/aandrewww/pino-sentry.svg?style=svg)](https://circleci.com/gh/aandrewww/pino-sentry) | ||
@@ -11,10 +11,10 @@ [![node](https://img.shields.io/badge/node-6.4.0+-brightgreen.svg)][node-url] | ||
* [Install](#install) | ||
* [Usage](#usage) | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [CLI](#cli) | ||
- [API](#api) | ||
* [Options](#options-options) | ||
- [Options](#options-options) | ||
- [Transport options](#transport-options) | ||
- [Log Level Mapping](#log-level-mapping) | ||
* [License](#license) | ||
- [License](#license) | ||
@@ -38,5 +38,7 @@ ## Install | ||
```js | ||
const { createWriteStream } = require('pino-sentry'); | ||
const { createWriteStream, Sentry } = require("pino-sentry"); | ||
// ... | ||
const opts = { /* ... */ }; | ||
const opts = { | ||
/* ... */ | ||
}; | ||
const stream = createWriteStream({ dsn: process.env.SENTRY_DSN }); | ||
@@ -46,6 +48,6 @@ const logger = pino(opts, stream); | ||
// add tags | ||
logger.info({ tags : { foo : "bar" }, msg : "Error" }); | ||
logger.info({ tags: { foo: "bar" }, msg: "Error" }); | ||
// add extra | ||
logger.info({ extra : { foo : "bar" }, msg : "Error" }); | ||
logger.info({ extra: { foo: "bar" }, msg: "Error" }); | ||
@@ -62,4 +64,13 @@ // add breadcrumbs | ||
}, | ||
] | ||
], | ||
}); | ||
// the sentry instance is exposed and can be used to manipulate the same sentry than pino-sentry | ||
Sentry.addBreadcrumb({ | ||
category: "custom-logger", | ||
message: "Hey there!", | ||
level: "debug", | ||
type: "debug", | ||
data: { some: "data" }, | ||
}); | ||
``` | ||
@@ -73,17 +84,29 @@ | ||
* `msg` | ||
* `extra` | ||
* `stack` | ||
* `maxValueLength` - option to adjust max string length for values, default is 250 | ||
- `msg` - the field used to get the message, it can be dot notted (eg 'data.msg') | ||
- `extra` | ||
- `stack` - the field used to get the stack, it can be dot notted (eg 'err.stack') | ||
- `maxValueLength` - option to adjust max string length for values, default is 250 | ||
- `decorateScope` - option to decorate, manipulate the sentry scope just before the capture | ||
- # `sentryExceptionLevels` - option that represent the levels that will be handled as exceptions. Default : `error` and `fatal` | ||
```js | ||
const { createWriteStream } = require('pino-sentry'); | ||
const { createWriteStream, Sentry } = require("pino-sentry"); | ||
// ... | ||
const opts = { /* ... */ }; | ||
const opts = { | ||
/* ... */ | ||
}; | ||
const stream = createWriteStream({ | ||
dsn: process.env.SENTRY_DSN, | ||
messageAttributeKey: 'message', | ||
stackAttributeKey: 'trace', | ||
extraAttributeKeys: ['req', 'context'], | ||
messageAttributeKey: "message", | ||
stackAttributeKey: "trace", | ||
extraAttributeKeys: ["req", "context"], | ||
maxValueLength: 250, | ||
sentryExceptionLevels: [ | ||
Sentry.Severity.Warning, | ||
Sentry.Severity.Error, | ||
Sentry.Severity.Fatal, | ||
], | ||
decorateScope: (data, scope) => { | ||
scope.setUser("userId", { id: data.userId }); | ||
}, | ||
}); | ||
@@ -95,9 +118,9 @@ const logger = pino(opts, stream); | ||
* `--dsn` (`-d`): your Sentry DSN or Data Source Name (defaults to `process.env.SENTRY_DSN`) | ||
* `--environment` (`-e`): (defaults to `process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || 'production'`) | ||
* `--serverName` (`-n`): transport name (defaults to `pino-sentry`) | ||
* `--debug` (`-dm`): turns debug mode on or off (default to `process.env.SENTRY_DEBUG || false`) | ||
* `--sampleRate` (`-sr`): sample rate as a percentage of events to be sent in the range of 0.0 to 1.0 (default to `1.0`) | ||
* `--maxBreadcrumbs` (`-mx`): total amount of breadcrumbs that should be captured (default to `100`) | ||
* `--level` (`-l`): minimum level for a log to be reported to Sentry (default to `debug`) | ||
- `--dsn` (`-d`): your Sentry DSN or Data Source Name (defaults to `process.env.SENTRY_DSN`) | ||
- `--environment` (`-e`): (defaults to `process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || 'production'`) | ||
- `--serverName` (`-n`): transport name (defaults to `pino-sentry`) | ||
- `--debug` (`-dm`): turns debug mode on or off (default to `process.env.SENTRY_DEBUG || false`) | ||
- `--sampleRate` (`-sr`): sample rate as a percentage of events to be sent in the range of 0.0 to 1.0 (default to `1.0`) | ||
- `--maxBreadcrumbs` (`-mx`): total amount of breadcrumbs that should be captured (default to `100`) | ||
- `--level` (`-l`): minimum level for a log to be reported to Sentry (default to `debug`) | ||
@@ -104,0 +127,0 @@ ### Log Level Mapping |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37279
326
142