Skip to content

Commit 4b20bfb

Browse files
HazATlobsterkatieSija
authored
fix: AWS Execution duration (#3032)
* fix: Execution duration * fix: StartTime * fix typo Co-authored-by: Sijawusz Pur Rahnama <[email protected]> Co-authored-by: Katie Byers <[email protected]> Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
1 parent d8ca29b commit 4b20bfb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/serverless/src/awslambda.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ export function init(options: Sentry.NodeOptions = {}): void {
6262
*
6363
* @param scope Scope that should be enhanced
6464
* @param context AWS Lambda context that will be used to extract some part of the data
65+
* @param startTime performance.now() when wrapHandler was invoked
6566
*/
66-
function enhanceScopeWithEnvironmentData(scope: Scope, context: Context): void {
67+
function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTime: number): void {
6768
scope.setTransactionName(context.functionName);
6869

6970
scope.setTag('server_name', process.env._AWS_XRAY_DAEMON_ADDRESS || process.env.SENTRY_NAME || hostname());
@@ -79,7 +80,7 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context): void {
7980
function_name: context.functionName,
8081
function_version: context.functionVersion,
8182
invoked_function_arn: context.invokedFunctionArn,
82-
execution_duration_in_millis: performance.now(),
83+
execution_duration_in_millis: performance.now() - startTime,
8384
remaining_time_in_millis: context.getRemainingTimeInMillis(),
8485
'sys.argv': process.argv,
8586
});
@@ -106,6 +107,7 @@ export function wrapHandler<TEvent, TResult>(
106107
handler: Handler<TEvent, TResult>,
107108
wrapOptions: Partial<WrapperOptions> = {},
108109
): Handler<TEvent, TResult | undefined> {
110+
const START_TIME = performance.now();
109111
const options: WrapperOptions = {
110112
flushTimeout: 2000,
111113
rethrowAfterCapture: true,
@@ -176,7 +178,7 @@ export function wrapHandler<TEvent, TResult>(
176178
const scope = hub.pushScope();
177179
let rv: TResult | undefined;
178180
try {
179-
enhanceScopeWithEnvironmentData(scope, context);
181+
enhanceScopeWithEnvironmentData(scope, context, START_TIME);
180182
// We put the transaction on the scope so users can attach children to it
181183
scope.setSpan(transaction);
182184
rv = await asyncHandler(event, context);

0 commit comments

Comments
 (0)