From 1b7d779334fe2d7126f33eee78f67668d52c5a91 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 5 Nov 2020 14:09:56 +0100 Subject: [PATCH 1/3] fix: Execution duration --- packages/serverless/src/awslambda.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index be6350b04fae..674ede3b9873 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -23,6 +23,7 @@ import { serverlessEventProcessor } from './utils'; export * from '@sentry/node'; const { isPromise } = types; +const START_TIME = performance.now(); // https://www.npmjs.com/package/aws-lambda-consumer type SyncHandler = ( @@ -79,7 +80,7 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context): void { function_name: context.functionName, function_version: context.functionVersion, invoked_function_arn: context.invokedFunctionArn, - execution_duration_in_millis: performance.now(), + execution_duration_in_millis: performance.now() - START_TIME, remaining_time_in_millis: context.getRemainingTimeInMillis(), 'sys.argv': process.argv, }); From 5ebf6865b9bf816bc4610fa3c19378d722b8e9bd Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 5 Nov 2020 15:24:06 +0100 Subject: [PATCH 2/3] fix: StartTime --- packages/serverless/src/awslambda.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index 674ede3b9873..b5cfeb324c8e 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -23,7 +23,6 @@ import { serverlessEventProcessor } from './utils'; export * from '@sentry/node'; const { isPromise } = types; -const START_TIME = performance.now(); // https://www.npmjs.com/package/aws-lambda-consumer type SyncHandler = ( @@ -63,8 +62,9 @@ export function init(options: Sentry.NodeOptions = {}): void { * * @param scope Scope that should be enhanced * @param context AWS Lambda context that will be used to extract some part of the data + * @param startTime performance.now() when warpHandler was invoked */ -function enhanceScopeWithEnvironmentData(scope: Scope, context: Context): void { +function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTime: number): void { scope.setTransactionName(context.functionName); scope.setTag('server_name', process.env._AWS_XRAY_DAEMON_ADDRESS || process.env.SENTRY_NAME || hostname()); @@ -80,7 +80,7 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context): void { function_name: context.functionName, function_version: context.functionVersion, invoked_function_arn: context.invokedFunctionArn, - execution_duration_in_millis: performance.now() - START_TIME, + execution_duration_in_millis: performance.now() - startTime, remaining_time_in_millis: context.getRemainingTimeInMillis(), 'sys.argv': process.argv, }); @@ -107,6 +107,7 @@ export function wrapHandler( handler: Handler, wrapOptions: Partial = {}, ): Handler { + const START_TIME = performance.now(); const options: WrapperOptions = { flushTimeout: 2000, rethrowAfterCapture: true, @@ -177,7 +178,7 @@ export function wrapHandler( const scope = hub.pushScope(); let rv: TResult | undefined; try { - enhanceScopeWithEnvironmentData(scope, context); + enhanceScopeWithEnvironmentData(scope, context, START_TIME); // We put the transaction on the scope so users can attach children to it scope.setSpan(transaction); rv = await asyncHandler(event, context); From 7d040b7aa5aacfebf45e368902fe6477099c6a4a Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 5 Nov 2020 14:24:13 -0800 Subject: [PATCH 3/3] fix typo Co-authored-by: Sijawusz Pur Rahnama --- packages/serverless/src/awslambda.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index b5cfeb324c8e..633bc1774a69 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -62,7 +62,7 @@ export function init(options: Sentry.NodeOptions = {}): void { * * @param scope Scope that should be enhanced * @param context AWS Lambda context that will be used to extract some part of the data - * @param startTime performance.now() when warpHandler was invoked + * @param startTime performance.now() when wrapHandler was invoked */ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTime: number): void { scope.setTransactionName(context.functionName);