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

ref(serverless): Remove rethrowAfterCapture use in AWS lambda wrapper #4448

Merged
merged 2 commits into from
Jan 25, 2022
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

This patch contains a breaking change for anyone setting the undocumented `rethrowAfterCapture` option for `@sentry/serverless`'s AWS wrapper to `false`, as its functionality has been removed. For backwards compatibility with anyone setting it to `true` (which is also the default), the option remains in the `WrapperOptions` type for now. It will be removed in the next major release, though, so we recommend removing it from your code.

- ref(serverless): Remove `rethrowAfterCapture` use in AWS lambda wrapper (#4448)

## 6.17.1

- ref(core): Renormalize event only after stringification errors (#4425)
Expand Down Expand Up @@ -945,7 +949,7 @@ removed in the future. If you are only using the `Tracing` integration there is

## 5.6.3

- [browser] fix: Don't capture our own XHR events that somehow bubbled-up to global handler
- [browser] fix: Don't capture our own XHR events that somehow bubbled-up to global handler (#2221)

## 5.6.2

Expand Down
12 changes: 5 additions & 7 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type AsyncHandler<T extends Handler> = (

export interface WrapperOptions {
flushTimeout: number;
rethrowAfterCapture: boolean;
// TODO: DEPRECATED - remove `rethrowAfterCapture` in v7
rethrowAfterCapture?: boolean;
callbackWaitsForEmptyEventLoop: boolean;
captureTimeoutWarning: boolean;
timeoutWarningLimit: number;
Expand Down Expand Up @@ -215,11 +216,10 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi
export function wrapHandler<TEvent, TResult>(
handler: Handler<TEvent, TResult>,
wrapOptions: Partial<WrapperOptions> = {},
): Handler<TEvent, TResult | undefined> {
): Handler<TEvent, TResult> {
const START_TIME = performance.now();
const options: WrapperOptions = {
flushTimeout: 2000,
rethrowAfterCapture: true,
callbackWaitsForEmptyEventLoop: false,
captureTimeoutWarning: true,
timeoutWarningLimit: 500,
Expand Down Expand Up @@ -293,7 +293,7 @@ export function wrapHandler<TEvent, TResult>(

const hub = getCurrentHub();
const scope = hub.pushScope();
let rv: TResult | undefined;
let rv: TResult;
try {
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
// We put the transaction on the scope so users can attach children to it
Expand All @@ -309,9 +309,7 @@ export function wrapHandler<TEvent, TResult>(
}
} catch (e) {
captureException(e);
if (options.rethrowAfterCapture) {
throw e;
}
throw e;
} finally {
clearTimeout(timeoutWarningTimer);
transaction.finish();
Expand Down
15 changes: 0 additions & 15 deletions packages/serverless/test/awslambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,6 @@ describe('AWSLambda', () => {
expect(Sentry.flush).toBeCalledWith(1337);
});

test('rethrowAfterCapture', async () => {
expect.assertions(3);

const error = new Error('wat');
const handler = () => {
throw error;
};
const wrappedHandlerWithRethrow = wrapHandler(handler, { rethrowAfterCapture: true });
const wrappedHandlerWithoutRethrow = wrapHandler(handler, { rethrowAfterCapture: false });

await expect(wrappedHandlerWithRethrow(fakeEvent, fakeContext, fakeCallback)).rejects.toThrow(error);
await expect(wrappedHandlerWithoutRethrow(fakeEvent, fakeContext, fakeCallback)).resolves.not.toThrow();
expect(Sentry.flush).toBeCalledTimes(2);
});

test('captureTimeoutWarning enabled (default)', async () => {
expect.assertions(2);

Expand Down