Skip to content

Commit

Permalink
fix: AWS Execution duration (#3032)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 12, 2020
1 parent d8ca29b commit 4b20bfb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,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 wrapHandler 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());
Expand All @@ -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() - startTime,
remaining_time_in_millis: context.getRemainingTimeInMillis(),
'sys.argv': process.argv,
});
Expand All @@ -106,6 +107,7 @@ export function wrapHandler<TEvent, TResult>(
handler: Handler<TEvent, TResult>,
wrapOptions: Partial<WrapperOptions> = {},
): Handler<TEvent, TResult | undefined> {
const START_TIME = performance.now();
const options: WrapperOptions = {
flushTimeout: 2000,
rethrowAfterCapture: true,
Expand Down Expand Up @@ -176,7 +178,7 @@ export function wrapHandler<TEvent, TResult>(
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);
Expand Down

0 comments on commit 4b20bfb

Please sign in to comment.