Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AWS Execution duration #3032

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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