From 563229f8631669c2ea4cda9609e17ba53c61609b Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 25 Oct 2023 10:17:04 -0400 Subject: [PATCH 1/2] fix(serverless): Don't mark all errors as unhandled --- packages/serverless/src/awslambda.ts | 3 +-- packages/serverless/src/gcpfunction/index.ts | 2 -- packages/serverless/src/utils.ts | 16 ---------------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index e29f77aaf879..78578083ee72 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -14,7 +14,7 @@ import { performance } from 'perf_hooks'; import { types } from 'util'; import { AWSServices } from './awsservices'; -import { markEventUnhandled, serverlessEventProcessor } from './utils'; +import { markEventUnhandled } from './utils'; export * from '@sentry/node'; @@ -88,7 +88,6 @@ export function init(options: AWSLambdaOptions = {}): void { }; Sentry.init(opts); - Sentry.addGlobalEventProcessor(serverlessEventProcessor); } /** */ diff --git a/packages/serverless/src/gcpfunction/index.ts b/packages/serverless/src/gcpfunction/index.ts index aa8f800d0d52..dc4358b30368 100644 --- a/packages/serverless/src/gcpfunction/index.ts +++ b/packages/serverless/src/gcpfunction/index.ts @@ -3,7 +3,6 @@ import type { Integration, SdkMetadata } from '@sentry/types'; import { GoogleCloudGrpc } from '../google-cloud-grpc'; import { GoogleCloudHttp } from '../google-cloud-http'; -import { serverlessEventProcessor } from '../utils'; export * from './http'; export * from './events'; @@ -38,5 +37,4 @@ export function init(options: Sentry.NodeOptions = {}): void { }; Sentry.init(opts); - Sentry.addGlobalEventProcessor(serverlessEventProcessor); } diff --git a/packages/serverless/src/utils.ts b/packages/serverless/src/utils.ts index 69e28ab3a823..c7377c39e73e 100644 --- a/packages/serverless/src/utils.ts +++ b/packages/serverless/src/utils.ts @@ -1,23 +1,7 @@ import { runWithAsyncContext } from '@sentry/core'; -import type { Event } from '@sentry/node'; import type { Scope } from '@sentry/types'; import { addExceptionMechanism } from '@sentry/utils'; -/** - * Event processor that will override SDK details to point to the serverless SDK instead of Node, - * as well as set correct mechanism type, which should be set to `handled: false`. - * We do it like this so that we don't introduce any side-effects in this module, which makes it tree-shakeable. - * @param event Event - * @param integration Name of the serverless integration ('AWSLambda', 'GCPFunction', etc) - */ -export function serverlessEventProcessor(event: Event): Event { - addExceptionMechanism(event, { - handled: false, - }); - - return event; -} - /** * @param fn function to run * @returns function which runs in the newly created domain or in the existing one From 1c221082b02d74ebc27d007d00657697c457c0e4 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 25 Oct 2023 10:20:21 -0400 Subject: [PATCH 2/2] fix tests --- packages/serverless/test/awslambda.test.ts | 25 -------------------- packages/serverless/test/gcpfunction.test.ts | 25 -------------------- 2 files changed, 50 deletions(-) diff --git a/packages/serverless/test/awslambda.test.ts b/packages/serverless/test/awslambda.test.ts index 199d0ac295ab..a3542d058121 100644 --- a/packages/serverless/test/awslambda.test.ts +++ b/packages/serverless/test/awslambda.test.ts @@ -534,30 +534,5 @@ describe('AWSLambda', () => { }), ); }); - - test('enhance event with correct mechanism value', () => { - const eventWithSomeData = { - exception: { - values: [{}], - }, - }; - - // @ts-expect-error see "Why @ts-expect-error" note - Sentry.addGlobalEventProcessor.mockImplementationOnce(cb => cb(eventWithSomeData)); - Sentry.AWSLambda.init({}); - - expect(eventWithSomeData).toEqual({ - exception: { - values: [ - { - mechanism: { - handled: false, - type: 'generic', - }, - }, - ], - }, - }); - }); }); }); diff --git a/packages/serverless/test/gcpfunction.test.ts b/packages/serverless/test/gcpfunction.test.ts index 5f830b05cdee..6aef838b1eb3 100644 --- a/packages/serverless/test/gcpfunction.test.ts +++ b/packages/serverless/test/gcpfunction.test.ts @@ -684,30 +684,5 @@ describe('GCPFunction', () => { }), ); }); - - test('enhance event with correct mechanism value', () => { - const eventWithSomeData = { - exception: { - values: [{}], - }, - }; - - // @ts-expect-error see "Why @ts-expect-error" note - Sentry.addGlobalEventProcessor.mockImplementationOnce(cb => cb(eventWithSomeData)); - Sentry.GCPFunction.init({}); - - expect(eventWithSomeData).toEqual({ - exception: { - values: [ - { - mechanism: { - handled: false, - type: 'generic', - }, - }, - ], - }, - }); - }); }); });