Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(serverless): Don't mark all errors as unhandled #9368

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
},
},
],
},
});
});
});
});