From dedc5cf14330e99ab699f30a65d14754d10bd7bb Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 24 Jan 2022 11:10:07 -0800 Subject: [PATCH 1/2] remove use of `rethrowAfterCapture` --- CHANGELOG.md | 6 +++++- packages/serverless/src/awslambda.ts | 12 +++++------- packages/serverless/test/awslambda.test.ts | 15 --------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f441c6422ae8..e9f8838ea860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. (That said, we couldn't find any projects in GitHub which do.) 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) @@ -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 diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index d6f99d9a85c3..4d1df2d9fec9 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -42,7 +42,8 @@ export type AsyncHandler = ( export interface WrapperOptions { flushTimeout: number; - rethrowAfterCapture: boolean; + // TODO: DEPRECATED - remove `rethrowAfterCapture` in v7 + rethrowAfterCapture?: boolean; callbackWaitsForEmptyEventLoop: boolean; captureTimeoutWarning: boolean; timeoutWarningLimit: number; @@ -215,11 +216,10 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi export function wrapHandler( handler: Handler, wrapOptions: Partial = {}, -): Handler { +): Handler { const START_TIME = performance.now(); const options: WrapperOptions = { flushTimeout: 2000, - rethrowAfterCapture: true, callbackWaitsForEmptyEventLoop: false, captureTimeoutWarning: true, timeoutWarningLimit: 500, @@ -293,7 +293,7 @@ export function wrapHandler( 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 @@ -309,9 +309,7 @@ export function wrapHandler( } } catch (e) { captureException(e); - if (options.rethrowAfterCapture) { - throw e; - } + throw e; } finally { clearTimeout(timeoutWarningTimer); transaction.finish(); diff --git a/packages/serverless/test/awslambda.test.ts b/packages/serverless/test/awslambda.test.ts index 18adc412a19f..a44f3281ba66 100644 --- a/packages/serverless/test/awslambda.test.ts +++ b/packages/serverless/test/awslambda.test.ts @@ -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); From 50bf505832f2e43c39fa34d555c52fc6e05c28d7 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 24 Jan 2022 15:56:59 -0800 Subject: [PATCH 2/2] remove parenthetical Co-authored-by: Abhijeet Prasad --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f8838ea860..e00f18378408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - "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. (That said, we couldn't find any projects in GitHub which do.) 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. +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)