Skip to content

Commit d356dc3

Browse files
committed
ref(serverless): Avoid using pushScope
This will be deprecated soon. Instead, use `withScope`.
1 parent 35906d0 commit d356dc3

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

packages/serverless/src/awslambda.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -319,35 +319,35 @@ export function wrapHandler<TEvent, TResult>(
319319
});
320320
}
321321

322-
const scope = hub.pushScope();
323-
let rv: TResult;
324-
try {
325-
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
326-
if (options.startTrace) {
327-
enhanceScopeWithTransactionData(scope, context);
328-
// We put the transaction on the scope so users can attach children to it
329-
scope.setSpan(transaction);
330-
}
331-
rv = await asyncHandler(event, context);
332-
333-
// We manage lambdas that use Promise.allSettled by capturing the errors of failed promises
334-
if (options.captureAllSettledReasons && Array.isArray(rv) && isPromiseAllSettledResult(rv)) {
335-
const reasons = getRejectedReasons(rv);
336-
reasons.forEach(exception => {
337-
captureException(exception, scope => markEventUnhandled(scope));
322+
return withScope(async scope => {
323+
let rv: TResult;
324+
try {
325+
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
326+
if (options.startTrace) {
327+
enhanceScopeWithTransactionData(scope, context);
328+
// We put the transaction on the scope so users can attach children to it
329+
scope.setSpan(transaction);
330+
}
331+
rv = await asyncHandler(event, context);
332+
333+
// We manage lambdas that use Promise.allSettled by capturing the errors of failed promises
334+
if (options.captureAllSettledReasons && Array.isArray(rv) && isPromiseAllSettledResult(rv)) {
335+
const reasons = getRejectedReasons(rv);
336+
reasons.forEach(exception => {
337+
captureException(exception, scope => markEventUnhandled(scope));
338+
});
339+
}
340+
} catch (e) {
341+
captureException(e, scope => markEventUnhandled(scope));
342+
throw e;
343+
} finally {
344+
clearTimeout(timeoutWarningTimer);
345+
transaction?.finish();
346+
await flush(options.flushTimeout).catch(e => {
347+
DEBUG_BUILD && logger.error(e);
338348
});
339349
}
340-
} catch (e) {
341-
captureException(e, scope => markEventUnhandled(scope));
342-
throw e;
343-
} finally {
344-
clearTimeout(timeoutWarningTimer);
345-
transaction?.finish();
346-
hub.popScope();
347-
await flush(options.flushTimeout).catch(e => {
348-
DEBUG_BUILD && logger.error(e);
349-
});
350-
}
351-
return rv;
350+
return rv;
351+
});
352352
};
353353
}

0 commit comments

Comments
 (0)