@venncity/errors
Advanced tools
Comparing version 1.7.16-addSentry.46 to 1.7.16-addSentry.80
@@ -1,2 +0,2 @@ | ||
import { CaptureContext } from '@sentry/types'; | ||
import * as Sentry from '@sentry/node'; | ||
import { APIGatewayProxyEvent } from 'aws-lambda'; | ||
@@ -11,4 +11,9 @@ interface AuthDetailsFromRequest { | ||
export declare function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest): void; | ||
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): void; | ||
export declare function flushErrors(timeout?: number): Promise<void>; | ||
export declare const sentry: { | ||
captureException: typeof Sentry.captureException; | ||
flush: typeof Sentry.flush; | ||
configureScope: typeof Sentry.configureScope; | ||
setTags: typeof Sentry.setTags; | ||
setContext: typeof Sentry.setContext; | ||
}; | ||
export declare function buildTags(event: Pick<APIGatewayProxyEvent, 'headers'>, { impersonated, isPublicAccess, isService, id, email }: AuthDetailsFromRequest): Record<string, string>; | ||
@@ -15,0 +20,0 @@ export declare function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & { |
@@ -21,23 +21,16 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildErrorContexts = exports.buildTags = exports.flushErrors = exports.reportErrorToSentry = exports.setupSentry = void 0; | ||
exports.buildErrorContexts = exports.buildTags = exports.sentry = exports.setupSentry = void 0; | ||
const lodash_1 = require("lodash"); | ||
const Sentry = __importStar(require("@sentry/node")); | ||
const SENTRY_DISABLED_LOG_LEVEL = process.env.stage === 'test' ? 'info' : 'warn'; | ||
// Run this ASAP so we won't miss errors that happen before init | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN, | ||
enabled: isSentryEnabled() | ||
}); | ||
function setupSentry(event, authDetailsFromRequest) { | ||
if (isSentryEnabled()) { | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN | ||
}); | ||
const tags = buildTags(event, authDetailsFromRequest); | ||
@@ -63,17 +56,10 @@ const contexts = buildErrorContexts(event); | ||
exports.setupSentry = setupSentry; | ||
function reportErrorToSentry(error, captureContext) { | ||
if (isSentryEnabled()) { | ||
Sentry.captureException(error, captureContext); | ||
} | ||
else { | ||
console[SENTRY_DISABLED_LOG_LEVEL]('Error not reported to sentry'); | ||
} | ||
} | ||
exports.reportErrorToSentry = reportErrorToSentry; | ||
function flushErrors(timeout = 2000) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Sentry.flush(timeout); | ||
}); | ||
} | ||
exports.flushErrors = flushErrors; | ||
// Wrapper for sentry object to allow us to replace the internal implementation in the future | ||
exports.sentry = { | ||
captureException: Sentry.captureException, | ||
flush: Sentry.flush, | ||
configureScope: Sentry.configureScope, | ||
setTags: Sentry.setTags, | ||
setContext: Sentry.setContext | ||
}; | ||
function isSentryEnabled() { | ||
@@ -105,7 +91,5 @@ const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true'; | ||
function buildErrorContexts(event) { | ||
const body = event.body && JSON.parse(event.body); | ||
const contexts = {}; | ||
contexts.records = event.Records; | ||
if (body) { | ||
contexts.requestBody = body; | ||
if (event.body) { | ||
contexts.requestBody = JSON.parse(event.body); | ||
} | ||
@@ -112,0 +96,0 @@ else if (event.Records) { |
@@ -37,6 +37,2 @@ "use strict"; | ||
const DUMMY_FUNCTION_NAME = 'dummy-function'; | ||
const DUMMY_ERROR = { | ||
message: 'some message', | ||
name: 'some name' | ||
}; | ||
describe('sentry error reporting', () => { | ||
@@ -72,2 +68,11 @@ let originalEnvVariables; | ||
}); | ||
test('User token - impersonated', () => { | ||
const authDetails = { | ||
id: 'sdvasdvsadv', | ||
email: 'moshe@ufnik.com', | ||
impersonated: true | ||
}; | ||
const tags = sentry.buildTags(testEvents.httpEvent, authDetails); | ||
expect(tags).toMatchSnapshot(); | ||
}); | ||
test('Public access token', () => { | ||
@@ -125,12 +130,3 @@ const authDetails = { | ||
}); | ||
describe('reportErrorToSentry', () => { | ||
test('sanity test - should not crash when sentry dsn is defined', () => __awaiter(void 0, void 0, void 0, function* () { | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
})); | ||
test('sanity test - should not crash when sentry dsn is not defined', () => __awaiter(void 0, void 0, void 0, function* () { | ||
delete process.env.SENTRY_DSN; | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
})); | ||
}); | ||
}); | ||
//# sourceMappingURL=sentry.test.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
const errors_1 = require("../errors/errors"); | ||
const sentry_1 = require("../errorReporting/sentry"); | ||
const __1 = require(".."); | ||
const config = require('@venncity/nested-config')(__dirname); | ||
@@ -17,6 +17,5 @@ const { VENN_ERROR, VENN_UNKNOWN_ERROR } = errors_1.codes; | ||
const logLevel = getLogLevelFromError(e); | ||
__1.sentry.setTags({ errorTraceId: e.traceId }); | ||
console[logLevel](e, `traceId=${e.traceId}`); | ||
const errorToThrow = errorResponse(e); | ||
sentry_1.reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } }); | ||
return errorToThrow; | ||
return errorResponse(e); | ||
} | ||
@@ -23,0 +22,0 @@ exports.handleErrorThrown = handleErrorThrown; |
@@ -5,3 +5,3 @@ import * as errors from './errors/errors'; | ||
import * as errorHandler from './errorHandler/errorHandler'; | ||
import * as errorReporting from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, errorReporting }; | ||
import { setupSentry, sentry } from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, setupSentry, sentry }; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errorReporting = exports.errorHandler = exports.errorFormatter = exports.validator = exports.errors = void 0; | ||
exports.sentry = exports.setupSentry = exports.errorHandler = exports.errorFormatter = exports.validator = exports.errors = void 0; | ||
const errors = __importStar(require("./errors/errors")); | ||
@@ -32,4 +32,5 @@ exports.errors = errors; | ||
exports.errorHandler = errorHandler; | ||
const errorReporting = __importStar(require("./errorReporting/sentry")); | ||
exports.errorReporting = errorReporting; | ||
const sentry_1 = require("./errorReporting/sentry"); | ||
Object.defineProperty(exports, "setupSentry", { enumerable: true, get: function () { return sentry_1.setupSentry; } }); | ||
Object.defineProperty(exports, "sentry", { enumerable: true, get: function () { return sentry_1.sentry; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { CaptureContext } from '@sentry/types'; | ||
import * as Sentry from '@sentry/node'; | ||
import { APIGatewayProxyEvent } from 'aws-lambda'; | ||
@@ -11,4 +11,9 @@ interface AuthDetailsFromRequest { | ||
export declare function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest): void; | ||
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): void; | ||
export declare function flushErrors(timeout?: number): Promise<void>; | ||
export declare const sentry: { | ||
captureException: typeof Sentry.captureException; | ||
flush: typeof Sentry.flush; | ||
configureScope: typeof Sentry.configureScope; | ||
setTags: typeof Sentry.setTags; | ||
setContext: typeof Sentry.setContext; | ||
}; | ||
export declare function buildTags(event: Pick<APIGatewayProxyEvent, 'headers'>, { impersonated, isPublicAccess, isService, id, email }: AuthDetailsFromRequest): Record<string, string>; | ||
@@ -15,0 +20,0 @@ export declare function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & { |
@@ -1,20 +0,13 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { get, pick } from 'lodash'; | ||
import * as Sentry from '@sentry/node'; | ||
const SENTRY_DISABLED_LOG_LEVEL = process.env.stage === 'test' ? 'info' : 'warn'; | ||
// Run this ASAP so we won't miss errors that happen before init | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN, | ||
enabled: isSentryEnabled() | ||
}); | ||
export function setupSentry(event, authDetailsFromRequest) { | ||
if (isSentryEnabled()) { | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN | ||
}); | ||
const tags = buildTags(event, authDetailsFromRequest); | ||
@@ -39,15 +32,10 @@ const contexts = buildErrorContexts(event); | ||
} | ||
export function reportErrorToSentry(error, captureContext) { | ||
if (isSentryEnabled()) { | ||
Sentry.captureException(error, captureContext); | ||
} | ||
else { | ||
console[SENTRY_DISABLED_LOG_LEVEL]('Error not reported to sentry'); | ||
} | ||
} | ||
export function flushErrors(timeout = 2000) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Sentry.flush(timeout); | ||
}); | ||
} | ||
// Wrapper for sentry object to allow us to replace the internal implementation in the future | ||
export const sentry = { | ||
captureException: Sentry.captureException, | ||
flush: Sentry.flush, | ||
configureScope: Sentry.configureScope, | ||
setTags: Sentry.setTags, | ||
setContext: Sentry.setContext | ||
}; | ||
function isSentryEnabled() { | ||
@@ -78,7 +66,5 @@ const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true'; | ||
export function buildErrorContexts(event) { | ||
const body = event.body && JSON.parse(event.body); | ||
const contexts = {}; | ||
contexts.records = event.Records; | ||
if (body) { | ||
contexts.requestBody = body; | ||
if (event.body) { | ||
contexts.requestBody = JSON.parse(event.body); | ||
} | ||
@@ -85,0 +71,0 @@ else if (event.Records) { |
@@ -16,6 +16,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const DUMMY_FUNCTION_NAME = 'dummy-function'; | ||
const DUMMY_ERROR = { | ||
message: 'some message', | ||
name: 'some name' | ||
}; | ||
describe('sentry error reporting', () => { | ||
@@ -51,2 +47,11 @@ let originalEnvVariables; | ||
}); | ||
test('User token - impersonated', () => { | ||
const authDetails = { | ||
id: 'sdvasdvsadv', | ||
email: 'moshe@ufnik.com', | ||
impersonated: true | ||
}; | ||
const tags = sentry.buildTags(testEvents.httpEvent, authDetails); | ||
expect(tags).toMatchSnapshot(); | ||
}); | ||
test('Public access token', () => { | ||
@@ -104,12 +109,3 @@ const authDetails = { | ||
}); | ||
describe('reportErrorToSentry', () => { | ||
test('sanity test - should not crash when sentry dsn is defined', () => __awaiter(void 0, void 0, void 0, function* () { | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
})); | ||
test('sanity test - should not crash when sentry dsn is not defined', () => __awaiter(void 0, void 0, void 0, function* () { | ||
delete process.env.SENTRY_DSN; | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
})); | ||
}); | ||
}); | ||
//# sourceMappingURL=sentry.test.js.map |
import { v4 as uuidv4 } from 'uuid'; | ||
import { VError, codes, SUPPORTED_LOG_LEVELS } from '../errors/errors'; | ||
import { reportErrorToSentry } from '../errorReporting/sentry'; | ||
import { sentry } from '..'; | ||
const config = require('@venncity/nested-config')(__dirname); | ||
@@ -13,6 +13,5 @@ const { VENN_ERROR, VENN_UNKNOWN_ERROR } = codes; | ||
const logLevel = getLogLevelFromError(e); | ||
sentry.setTags({ errorTraceId: e.traceId }); | ||
console[logLevel](e, `traceId=${e.traceId}`); | ||
const errorToThrow = errorResponse(e); | ||
reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } }); | ||
return errorToThrow; | ||
return errorResponse(e); | ||
} | ||
@@ -19,0 +18,0 @@ function getLogLevelFromError(e) { |
@@ -5,3 +5,3 @@ import * as errors from './errors/errors'; | ||
import * as errorHandler from './errorHandler/errorHandler'; | ||
import * as errorReporting from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, errorReporting }; | ||
import { setupSentry, sentry } from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, setupSentry, sentry }; |
@@ -5,4 +5,4 @@ import * as errors from './errors/errors'; | ||
import * as errorHandler from './errorHandler/errorHandler'; | ||
import * as errorReporting from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, errorReporting }; | ||
import { setupSentry, sentry } from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, setupSentry, sentry }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@venncity/errors", | ||
"version": "1.7.16-addSentry.46+77f267111", | ||
"version": "1.7.16-addSentry.80+1e4e96752", | ||
"author": "Venn Engineering", | ||
@@ -36,3 +36,3 @@ "main": "lib/cjs/index.js", | ||
"@sentry/types": "^5.21.1", | ||
"@venncity/nested-config": "^2.0.24-addSentry.46+77f267111", | ||
"@venncity/nested-config": "^2.0.24-addSentry.80+1e4e96752", | ||
"fast-safe-stringify": "^2.0.7", | ||
@@ -44,3 +44,3 @@ "joi": "^14.3.1", | ||
}, | ||
"gitHead": "77f26711109cd0883daa6463f1fab6d0df038edd" | ||
"gitHead": "1e4e96752aad0f85761e59d23b4759ea1b019cc7" | ||
} |
@@ -9,9 +9,5 @@ import * as sentry from './sentry'; | ||
const DUMMY_FUNCTION_NAME = 'dummy-function'; | ||
const DUMMY_ERROR: Error = { | ||
message: 'some message', | ||
name: 'some name' | ||
}; | ||
describe('sentry error reporting', () => { | ||
let originalEnvVariables; | ||
let originalEnvVariables: Record<string, string | undefined>; | ||
beforeAll(() => { | ||
@@ -48,2 +44,11 @@ originalEnvVariables = { | ||
}); | ||
test('User token - impersonated', () => { | ||
const authDetails = { | ||
id: 'sdvasdvsadv', | ||
email: 'moshe@ufnik.com', | ||
impersonated: true | ||
}; | ||
const tags = sentry.buildTags(testEvents.httpEvent, authDetails); | ||
expect(tags).toMatchSnapshot(); | ||
}); | ||
test('Public access token', () => { | ||
@@ -103,11 +108,2 @@ const authDetails = { | ||
}); | ||
describe('reportErrorToSentry', () => { | ||
test('sanity test - should not crash when sentry dsn is defined', async () => { | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
}); | ||
test('sanity test - should not crash when sentry dsn is not defined', async () => { | ||
delete process.env.SENTRY_DSN; | ||
sentry.reportErrorToSentry(DUMMY_ERROR); | ||
}); | ||
}); | ||
}); |
import { get, pick } from 'lodash'; | ||
import { CaptureContext } from '@sentry/types'; | ||
import * as Sentry from '@sentry/node'; | ||
@@ -17,12 +16,14 @@ // eslint-disable-next-line import/no-extraneous-dependencies | ||
// Run this ASAP so we won't miss errors that happen before init | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN, | ||
enabled: isSentryEnabled() | ||
}); | ||
export function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest) { | ||
if (isSentryEnabled()) { | ||
Sentry.init({ | ||
environment: process.env.STAGE, | ||
serverName: process.env.SERVICE_NAME, | ||
dsn: process.env.SENTRY_DSN | ||
}); | ||
const tags = buildTags(event, authDetailsFromRequest); | ||
const contexts = buildErrorContexts(event); | ||
Sentry.configureScope((scope) => { | ||
@@ -45,14 +46,11 @@ if (authDetailsFromRequest.email) { | ||
export function reportErrorToSentry(error: Error, captureContext?: CaptureContext) { | ||
if (isSentryEnabled()) { | ||
Sentry.captureException(error, captureContext); | ||
} else { | ||
console[SENTRY_DISABLED_LOG_LEVEL]('Error not reported to sentry'); | ||
} | ||
} | ||
// Wrapper for sentry object to allow us to replace the internal implementation in the future | ||
export const sentry = { | ||
captureException: Sentry.captureException, | ||
flush: Sentry.flush, | ||
configureScope: Sentry.configureScope, | ||
setTags: Sentry.setTags, | ||
setContext: Sentry.setContext | ||
}; | ||
export async function flushErrors(timeout = 2000) { | ||
await Sentry.flush(timeout); | ||
} | ||
function isSentryEnabled() { | ||
@@ -84,7 +82,5 @@ const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true'; | ||
export function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & { Records?: any }): Record<string, any> { | ||
const body = event.body && JSON.parse(event.body); | ||
const contexts: Record<string, any> = {}; | ||
contexts.records = event.Records; | ||
if (body) { | ||
contexts.requestBody = body; | ||
if (event.body) { | ||
contexts.requestBody = JSON.parse(event.body); | ||
} else if (event.Records) { | ||
@@ -91,0 +87,0 @@ contexts.records = event.Records.map((record) => { |
import { v4 as uuidv4 } from 'uuid'; | ||
import { VError, codes, SUPPORTED_LOG_LEVELS } from '../errors/errors'; | ||
import { reportErrorToSentry } from '../errorReporting/sentry'; | ||
import { sentry } from '..'; | ||
@@ -17,6 +17,5 @@ const config = require('@venncity/nested-config')(__dirname); | ||
const logLevel = getLogLevelFromError(e); | ||
sentry.setTags({ errorTraceId: e.traceId }); | ||
console[logLevel](e, `traceId=${e.traceId}`); | ||
const errorToThrow = errorResponse(e); | ||
reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } }); | ||
return errorToThrow; | ||
return errorResponse(e); | ||
} | ||
@@ -23,0 +22,0 @@ |
@@ -5,5 +5,4 @@ import * as errors from './errors/errors'; | ||
import * as errorHandler from './errorHandler/errorHandler'; | ||
import * as errorReporting from './errorReporting/sentry'; | ||
import { setupSentry, sentry } from './errorReporting/sentry'; | ||
export { errors, validator, errorFormatter, errorHandler, errorReporting }; | ||
export { errors, validator, errorFormatter, errorHandler, setupSentry, sentry }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
41
201628
3310