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

@venncity/errors

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@venncity/errors - npm Package Compare versions

Comparing version 1.7.16-addSentry.33 to 1.7.16-addSentry.46

lib/cjs/errorReporting/sentry.test.d.ts

7

lib/cjs/errorReporting/sentry.d.ts

@@ -11,3 +11,8 @@ import { CaptureContext } from '@sentry/types';

export declare function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest): void;
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): Promise<void>;
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): void;
export declare function flushErrors(timeout?: number): Promise<void>;
export declare function buildTags(event: Pick<APIGatewayProxyEvent, 'headers'>, { impersonated, isPublicAccess, isService, id, email }: AuthDetailsFromRequest): Record<string, string>;
export declare function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & {
Records?: any;
}): Record<string, any>;
export {};

46

lib/cjs/errorReporting/sentry.js

@@ -31,5 +31,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.reportErrorToSentry = exports.setupSentry = void 0;
exports.buildErrorContexts = exports.buildTags = exports.flushErrors = exports.reportErrorToSentry = 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';
function setupSentry(event, authDetailsFromRequest) {

@@ -56,3 +57,3 @@ if (isSentryEnabled()) {

else {
console.info(`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
console[SENTRY_DISABLED_LOG_LEVEL](`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
To enable it create a project in sentry for the service and set the SENTRY_DSN env variable

@@ -64,17 +65,22 @@ to contain the dsn`);

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* () {
if (isSentryEnabled()) {
Sentry.captureException(error, captureContext);
yield Sentry.flush(2000);
}
else {
console.warn('Error not reported to sentry because sentry is not set up');
}
yield Sentry.flush(timeout);
});
}
exports.reportErrorToSentry = reportErrorToSentry;
exports.flushErrors = flushErrors;
function isSentryEnabled() {
return !!process.env.SENTRY_DSN;
const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true';
return !!process.env.SENTRY_DSN && shouldSendErrorsForEnv;
}
function buildTags(event, { impersonated, isPublicAccess, isService, id }) {
// eslint-disable-next-line max-len
function buildTags(event, { impersonated, isPublicAccess, isService, id, email }) {
const tags = {};

@@ -84,3 +90,5 @@ tags.xrayTraceId = lodash_1.get(event, 'headers.xrayTraceId');

tags.functionName = process.env.FUNCTION_NAME;
tags['auth.impersonated'] = Boolean(impersonated).toString();
if (impersonated) {
tags['auth.impersonated'] = 'true';
}
if (isPublicAccess) {

@@ -92,4 +100,8 @@ tags['auth.publicToken'] = Boolean(isPublicAccess).toString();

}
else if (email) {
tags['auth.userEmail'] = email;
}
return tags;
}
exports.buildTags = buildTags;
function buildErrorContexts(event) {

@@ -101,7 +113,11 @@ const body = event.body && JSON.parse(event.body);

contexts.requestBody = body;
contexts.query = body.query;
contexts.variables = body.variables;
}
else if (event.Records) {
contexts.records = event.Records.map((record) => {
return Object.assign(Object.assign({}, lodash_1.pick(record, ['messageId', 'messageAttributes', 'eventSource', 'eventSourceARN'])), { body: record.body && JSON.parse(record.body) });
});
}
return contexts;
}
exports.buildErrorContexts = buildErrorContexts;
//# sourceMappingURL=sentry.js.map

@@ -19,14 +19,5 @@ "use strict";

sentry_1.reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } });
// Since this is a sync function we cannot await the reportErrorToSentry call.
// flushing to sentry takes time so we need to wait here in a sync manner
sleepSync(2000);
return errorToThrow;
}
exports.handleErrorThrown = handleErrorThrown;
function sleepSync(ms) {
console.log('Sleeping for ', ms, ' millis');
const start = new Date().getTime();
const expire = start + ms;
while (new Date().getTime() < expire) { }
}
function getLogLevelFromError(e) {

@@ -33,0 +24,0 @@ return e.logLevel || ERROR;

@@ -11,3 +11,8 @@ import { CaptureContext } from '@sentry/types';

export declare function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest): void;
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): Promise<void>;
export declare function reportErrorToSentry(error: Error, captureContext?: CaptureContext): void;
export declare function flushErrors(timeout?: number): Promise<void>;
export declare function buildTags(event: Pick<APIGatewayProxyEvent, 'headers'>, { impersonated, isPublicAccess, isService, id, email }: AuthDetailsFromRequest): Record<string, string>;
export declare function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & {
Records?: any;
}): Record<string, any>;
export {};

@@ -10,4 +10,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { get } from 'lodash';
import { get, pick } from 'lodash';
import * as Sentry from '@sentry/node';
const SENTRY_DISABLED_LOG_LEVEL = process.env.stage === 'test' ? 'info' : 'warn';
export function setupSentry(event, authDetailsFromRequest) {

@@ -34,3 +35,3 @@ if (isSentryEnabled()) {

else {
console.info(`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
console[SENTRY_DISABLED_LOG_LEVEL](`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
To enable it create a project in sentry for the service and set the SENTRY_DSN env variable

@@ -41,16 +42,20 @@ to contain the dsn`);

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* () {
if (isSentryEnabled()) {
Sentry.captureException(error, captureContext);
yield Sentry.flush(2000);
}
else {
console.warn('Error not reported to sentry because sentry is not set up');
}
yield Sentry.flush(timeout);
});
}
function isSentryEnabled() {
return !!process.env.SENTRY_DSN;
const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true';
return !!process.env.SENTRY_DSN && shouldSendErrorsForEnv;
}
function buildTags(event, { impersonated, isPublicAccess, isService, id }) {
// eslint-disable-next-line max-len
export function buildTags(event, { impersonated, isPublicAccess, isService, id, email }) {
const tags = {};

@@ -60,3 +65,5 @@ tags.xrayTraceId = get(event, 'headers.xrayTraceId');

tags.functionName = process.env.FUNCTION_NAME;
tags['auth.impersonated'] = Boolean(impersonated).toString();
if (impersonated) {
tags['auth.impersonated'] = 'true';
}
if (isPublicAccess) {

@@ -68,5 +75,8 @@ tags['auth.publicToken'] = Boolean(isPublicAccess).toString();

}
else if (email) {
tags['auth.userEmail'] = email;
}
return tags;
}
function buildErrorContexts(event) {
export function buildErrorContexts(event) {
const body = event.body && JSON.parse(event.body);

@@ -77,7 +87,10 @@ const contexts = {};

contexts.requestBody = body;
contexts.query = body.query;
contexts.variables = body.variables;
}
else if (event.Records) {
contexts.records = event.Records.map((record) => {
return Object.assign(Object.assign({}, pick(record, ['messageId', 'messageAttributes', 'eventSource', 'eventSourceARN'])), { body: record.body && JSON.parse(record.body) });
});
}
return contexts;
}
//# sourceMappingURL=sentry.js.map

@@ -16,13 +16,4 @@ import { v4 as uuidv4 } from 'uuid';

reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } });
// Since this is a sync function we cannot await the reportErrorToSentry call.
// flushing to sentry takes time so we need to wait here in a sync manner
sleepSync(2000);
return errorToThrow;
}
function sleepSync(ms) {
console.log('Sleeping for ', ms, ' millis');
const start = new Date().getTime();
const expire = start + ms;
while (new Date().getTime() < expire) { }
}
function getLogLevelFromError(e) {

@@ -29,0 +20,0 @@ return e.logLevel || ERROR;

{
"name": "@venncity/errors",
"version": "1.7.16-addSentry.33+6e346ab71",
"version": "1.7.16-addSentry.46+77f267111",
"author": "Venn Engineering",

@@ -36,3 +36,3 @@ "main": "lib/cjs/index.js",

"@sentry/types": "^5.21.1",
"@venncity/nested-config": "^2.0.24-addSentry.33+6e346ab71",
"@venncity/nested-config": "^2.0.24-addSentry.46+77f267111",
"fast-safe-stringify": "^2.0.7",

@@ -44,3 +44,3 @@ "joi": "^14.3.1",

},
"gitHead": "6e346ab71d48a873546ca9dc54be47d4805fb3e0"
"gitHead": "77f26711109cd0883daa6463f1fab6d0df038edd"
}

@@ -1,4 +0,4 @@

import { get } from 'lodash';
import { get, pick } from 'lodash';
import { CaptureContext } from '@sentry/types';
import * as Sentry from '@sentry/node';
import { CaptureContext } from '@sentry/types';
// eslint-disable-next-line import/no-extraneous-dependencies

@@ -15,2 +15,4 @@ import { APIGatewayProxyEvent } from 'aws-lambda';

const SENTRY_DISABLED_LOG_LEVEL = process.env.stage === 'test' ? 'info' : 'warn';
export function setupSentry(event: APIGatewayProxyEvent, authDetailsFromRequest: AuthDetailsFromRequest) {

@@ -37,3 +39,3 @@ if (isSentryEnabled()) {

} else {
console.info(`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
console[SENTRY_DISABLED_LOG_LEVEL](`Sentry is not enabled for service ${process.env.SERVICE_NAME}.
To enable it create a project in sentry for the service and set the SENTRY_DSN env variable

@@ -44,16 +46,21 @@ to contain the dsn`);

export async function reportErrorToSentry(error: Error, captureContext?: CaptureContext) {
export function reportErrorToSentry(error: Error, captureContext?: CaptureContext) {
if (isSentryEnabled()) {
Sentry.captureException(error, captureContext);
await Sentry.flush(2000);
} else {
console.warn('Error not reported to sentry because sentry is not set up');
console[SENTRY_DISABLED_LOG_LEVEL]('Error not reported to sentry');
}
}
export async function flushErrors(timeout = 2000) {
await Sentry.flush(timeout);
}
function isSentryEnabled() {
return !!process.env.SENTRY_DSN;
const shouldSendErrorsForEnv = process.env.stage !== 'test' || process.env.REPORT_ERRORS_IN_TEST === 'true';
return !!process.env.SENTRY_DSN && shouldSendErrorsForEnv;
}
function buildTags(event: APIGatewayProxyEvent, { impersonated, isPublicAccess, isService, id }: AuthDetailsFromRequest) {
// eslint-disable-next-line max-len
export function buildTags(event: Pick<APIGatewayProxyEvent, 'headers'>, { impersonated, isPublicAccess, isService, id, email }: AuthDetailsFromRequest) {
const tags: Record<string, string> = {};

@@ -63,3 +70,5 @@ tags.xrayTraceId = get(event, 'headers.xrayTraceId');

tags.functionName = process.env.FUNCTION_NAME;
tags['auth.impersonated'] = Boolean(impersonated).toString();
if (impersonated) {
tags['auth.impersonated'] = 'true';
}

@@ -70,2 +79,4 @@ if (isPublicAccess) {

tags['auth.serviceToken'] = id;
} else if (email) {
tags['auth.userEmail'] = email;
}

@@ -75,3 +86,3 @@ return tags;

function buildErrorContexts(event: APIGatewayProxyEvent & { Records?: any }): Record<string, any> {
export function buildErrorContexts(event: Pick<APIGatewayProxyEvent, 'body'> & { Records?: any }): Record<string, any> {
const body = event.body && JSON.parse(event.body);

@@ -82,6 +93,11 @@ const contexts: Record<string, any> = {};

contexts.requestBody = body;
contexts.query = body.query;
contexts.variables = body.variables;
} else if (event.Records) {
contexts.records = event.Records.map((record) => {
return {
...pick(record, ['messageId', 'messageAttributes', 'eventSource', 'eventSourceARN']),
body: record.body && JSON.parse(record.body)
};
});
}
return contexts;
}

@@ -20,15 +20,5 @@ import { v4 as uuidv4 } from 'uuid';

reportErrorToSentry(e, { level: logLevel, tags: { traceId: e.traceId }, contexts: { errorThrown: errorToThrow } });
// Since this is a sync function we cannot await the reportErrorToSentry call.
// flushing to sentry takes time so we need to wait here in a sync manner
sleepSync(2000);
return errorToThrow;
}
function sleepSync(ms) {
console.log('Sleeping for ', ms, ' millis');
const start = new Date().getTime();
const expire = start + ms;
while (new Date().getTime() < expire) { }
}
function getLogLevelFromError(e) {

@@ -35,0 +25,0 @@ return e.logLevel || ERROR;

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

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