Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino-sentry

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-sentry - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

15

dist/cli.js
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const commander_1 = tslib_1.__importDefault(require("commander"));
const commander_1 = __importDefault(require("commander"));
// import pkg from '../package.json';

@@ -21,5 +23,5 @@ const transport_1 = require("./transport");

.option('--release <release>', 'The release identifier used when uploading respective source maps.')
.action(async ({ dsn, serverName, environment, debug, sampleRate, maxBreadcrumbs, dist, logLevel, maxValueLength, release }) => {
.option('-l, --level <level>', 'The minimum level for a log to be reported to Sentry')
.action(async ({ dsn, serverName, environment, debug, sampleRate, maxBreadcrumbs, dist, logLevel, maxValueLength, release, level }) => {
try {
console.info('start');
const writeStream = await transport_1.createWriteStreamAsync({

@@ -36,8 +38,9 @@ dsn,

release,
level,
});
process.stdin.pipe(writeStream);
console.info('logging');
console.info('[pino-sentry] logging initialized');
}
catch (error) {
console.log(error.message);
console.log(`[pino-sentry] ${error.message}`);
}

@@ -44,0 +47,0 @@ });

26

dist/transport.d.ts
/// <reference types="node" />
import stream from 'stream';
import * as Sentry from '@sentry/node';
declare type ValueOf<T> = T extends any[] ? T[number] : T[keyof T];
declare const SEVERITIES_MAP: {

@@ -18,4 +19,18 @@ readonly 10: Sentry.Severity.Debug;

};
declare const SeverityIota: {
readonly [Sentry.Severity.Debug]: 1;
readonly [Sentry.Severity.Log]: 2;
readonly [Sentry.Severity.Info]: 3;
readonly [Sentry.Severity.Warning]: 4;
readonly [Sentry.Severity.Error]: 5;
readonly [Sentry.Severity.Fatal]: 6;
readonly [Sentry.Severity.Critical]: 7;
};
interface PinoSentryOptions extends Sentry.NodeOptions {
/** Minimum level for a log to be reported to Sentry from pino-sentry */
level?: keyof typeof SeverityIota;
}
export declare class PinoSentryTransport {
constructor(options?: Sentry.NodeOptions);
minimumLogLevel: ValueOf<typeof SeverityIota>;
constructor(options?: PinoSentryOptions);
getLogSeverity(level: keyof typeof SEVERITIES_MAP): Sentry.Severity;

@@ -26,10 +41,11 @@ readonly sentry: typeof Sentry;

prepareAndGo(chunk: any, cb: any): void;
private withDefaults;
private validateOptions;
private isObject;
private shouldLogException;
private isSentryException;
private shouldLog;
}
export declare function createWriteStreamAsync(options?: Sentry.NodeOptions): PromiseLike<stream.Transform>;
export declare function createWriteStream(options?: Sentry.NodeOptions): stream.Transform & {
export declare function createWriteStreamAsync(options?: PinoSentryOptions): PromiseLike<stream.Transform>;
export declare function createWriteStream(options?: PinoSentryOptions): stream.Transform & {
transport: PinoSentryTransport;
};
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const split2_1 = tslib_1.__importDefault(require("split2"));
const pump_1 = tslib_1.__importDefault(require("pump"));
const through2_1 = tslib_1.__importDefault(require("through2"));
const pify_1 = tslib_1.__importDefault(require("pify"));
const Sentry = tslib_1.__importStar(require("@sentry/node"));
const split2_1 = __importDefault(require("split2"));
const pump_1 = __importDefault(require("pump"));
const through2_1 = __importDefault(require("through2"));
const pify_1 = __importDefault(require("pify"));
const Sentry = __importStar(require("@sentry/node"));
class ExtendedError extends Error {

@@ -39,5 +48,17 @@ constructor(info) {

};
// How severe the Severity is
const SeverityIota = {
[Sentry.Severity.Debug]: 1,
[Sentry.Severity.Log]: 2,
[Sentry.Severity.Info]: 3,
[Sentry.Severity.Warning]: 4,
[Sentry.Severity.Error]: 5,
[Sentry.Severity.Fatal]: 6,
[Sentry.Severity.Critical]: 7,
};
class PinoSentryTransport {
constructor(options) {
Sentry.init(this.withDefaults(options || {}));
// Default minimum log level to `debug`
this.minimumLogLevel = SeverityIota[Sentry.Severity.Debug];
Sentry.init(this.validateOptions(options || {}));
}

@@ -63,2 +84,8 @@ getLogSeverity(level) {

const severity = this.getLogSeverity(chunk.level);
// Check if we send this Severity to Sentry
if (this.shouldLog(severity) === false) {
setImmediate(cb);
return;
}
;
const tags = chunk.tags || {};

@@ -83,3 +110,3 @@ if (chunk.reqId) {

// Capturing Errors / Exceptions
if (this.shouldLogException(severity)) {
if (this.isSentryException(severity)) {
const error = message instanceof Error ? message : new ExtendedError({ message, stack });

@@ -99,5 +126,17 @@ setImmediate(() => {

}
withDefaults(options = {}) {
validateOptions(options) {
const dsn = options.dsn || process.env.SENTRY_DSN;
if (!dsn) {
throw Error('[pino-sentry] Sentry DSN must be supplied. Pass via options or `SENTRY_DSN` environment variable');
}
if (options.level) {
const allowedLevels = Object.keys(SeverityIota);
if (allowedLevels.includes(options.level) === false) {
throw new Error(`[pino-sentry] Option \`level\` must be one of: ${allowedLevels.join(', ')}. Received: ${options.level}`);
}
// Set minimum log level
this.minimumLogLevel = SeverityIota[options.level];
}
return {
dsn: process.env.SENTRY_DSN || '',
dsn,
// npm_package_name will be available if ran with

@@ -117,12 +156,13 @@ // from a "script" field in package.json.

}
shouldLogException(level) {
isSentryException(level) {
return level === Sentry.Severity.Fatal || level === Sentry.Severity.Error;
}
shouldLog(severity) {
const logLevel = SeverityIota[severity];
return logLevel >= this.minimumLogLevel;
}
}
exports.PinoSentryTransport = PinoSentryTransport;
;
function createWriteStreamAsync(options = {}) {
if (!options.dsn && !process.env.SENTRY_DSN) {
throw Error('Sentry DSN missing');
}
function createWriteStreamAsync(options) {
const transport = new PinoSentryTransport(options);

@@ -142,6 +182,3 @@ const sentryTransformer = transport.transformer();

;
function createWriteStream(options = {}) {
if (!options.dsn && !process.env.SENTRY_DSN) {
throw Error('Sentry DSN missing');
}
function createWriteStream(options) {
const transport = new PinoSentryTransport(options);

@@ -148,0 +185,0 @@ const sentryParse = transport.parse.bind(transport);

{
"name": "pino-sentry",
"description": "@sentry/node transport for pino logger",
"version": "0.3.0",
"version": "0.4.0",
"author": "Andrew Avdeev <andrewww.avdeev@gmail.com>",

@@ -37,3 +37,3 @@ "keywords": [

"dependencies": {
"@sentry/node": "^5.5.0",
"@sentry/node": "^5.21.1",
"commander": "^2.20.0",

@@ -40,0 +40,0 @@ "pify": "^4.0.1",

@@ -54,2 +54,3 @@

* `--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`)

@@ -56,0 +57,0 @@ ### Log Level Mapping

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc