From a4c32f09ab9b34d1c76c24fc599c683f97bf28ba Mon Sep 17 00:00:00 2001 From: Tomasz Pytel Date: Wed, 23 Feb 2022 11:42:49 -0300 Subject: [PATCH 1/2] fix awaits and SW_AWSLAMBDA_FLUSH default --- src/aws/AWSLambdaTriggerPlugin.ts | 4 ++-- src/config/AgentConfig.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aws/AWSLambdaTriggerPlugin.ts b/src/aws/AWSLambdaTriggerPlugin.ts index efe0250..d4bba31 100644 --- a/src/aws/AWSLambdaTriggerPlugin.ts +++ b/src/aws/AWSLambdaTriggerPlugin.ts @@ -85,10 +85,10 @@ class AWSLambdaTriggerPlugin { // generic Promise check ret = callbackPromise; - return stop(null, await ret); + return await stop(null, await ret); } catch (e) { span.error(e); - stop(e, null); + await stop(e, null); throw e; } diff --git a/src/config/AgentConfig.ts b/src/config/AgentConfig.ts index e9ff4e3..1784ced 100644 --- a/src/config/AgentConfig.ts +++ b/src/config/AgentConfig.ts @@ -112,7 +112,7 @@ const _config = { sqlParametersMaxLength: Math.trunc(Math.max(0, Number(process.env.SW_SQL_PARAMETERS_MAX_LENGTH))) || 512, mongoTraceParameters: (process.env.SW_MONGO_TRACE_PARAMETERS || '').toLowerCase() === 'true', mongoParametersMaxLength: Math.trunc(Math.max(0, Number(process.env.SW_MONGO_PARAMETERS_MAX_LENGTH))) || 512, - awsLambdaFlush: (process.env.SW_AWSLAMBDA_FLUSH || '').toLowerCase() === 'true', + awsLambdaFlush: (process.env.SW_AWSLAMBDA_FLUSH || 'true').toLowerCase() === 'true', reDisablePlugins: RegExp(''), // temporary placeholder so Typescript doesn't throw a fit reIgnoreOperation: RegExp(''), reHttpIgnoreMethod: RegExp(''), From 9cfcc6d74d1cf774112870335654770a804bffc2 Mon Sep 17 00:00:00 2001 From: Tomasz Pytel Date: Wed, 23 Feb 2022 13:02:47 -0300 Subject: [PATCH 2/2] let event loop tick once before AWSLambda flush --- src/aws/AWSLambdaTriggerPlugin.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/aws/AWSLambdaTriggerPlugin.ts b/src/aws/AWSLambdaTriggerPlugin.ts index d4bba31..bd91e8b 100644 --- a/src/aws/AWSLambdaTriggerPlugin.ts +++ b/src/aws/AWSLambdaTriggerPlugin.ts @@ -54,6 +54,8 @@ class AWSLambdaTriggerPlugin { this.stop(span, err, res); if (config.awsLambdaFlush) { + await new Promise((resolve) => setTimeout(resolve, 0)); // child spans of this span may have finalization waiting in the event loop in which case we give them a chance to run so that the segment can be archived properly for flushing + const p = agent.flush(); // flush all data before aws freezes the process on exit if (p) await p;