Skip to content

Commit

Permalink
fix(serverless): Don't mark all errors as unhandled (#9368)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Oct 25, 2023
1 parent 207b0bc commit 39ba7d4
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 70 deletions.
3 changes: 1 addition & 2 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -88,7 +88,6 @@ export function init(options: AWSLambdaOptions = {}): void {
};

Sentry.init(opts);
Sentry.addGlobalEventProcessor(serverlessEventProcessor);
}

/** */
Expand Down
2 changes: 0 additions & 2 deletions packages/serverless/src/gcpfunction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,5 +37,4 @@ export function init(options: Sentry.NodeOptions = {}): void {
};

Sentry.init(opts);
Sentry.addGlobalEventProcessor(serverlessEventProcessor);
}
16 changes: 0 additions & 16 deletions packages/serverless/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 0 additions & 25 deletions packages/serverless/test/awslambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
},
});
});
});
});
25 changes: 0 additions & 25 deletions packages/serverless/test/gcpfunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
},
});
});
});
});

0 comments on commit 39ba7d4

Please sign in to comment.