Skip to content

Commit 050662c

Browse files
committed
add missing await and move metrics block
1 parent 02e9ae7 commit 050662c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/handler.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let wrapped_handler;
3737
try {
3838
wrapped_handler = datadog(await load(taskRootEnv, handlerEnv), { traceExtractor });
3939
} catch (error) {
40-
emitTelemetryOnErrorOutsideHandler(error, handlerEnv, Date.now());
40+
await emitTelemetryOnErrorOutsideHandler(error, handlerEnv, Date.now());
4141
throw error;
4242
}
4343

src/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,6 @@ export async function emitTelemetryOnErrorOutsideHandler(
424424
functionName: string,
425425
startTime: number,
426426
): Promise<void> {
427-
const config = getConfig();
428-
const metricsListener = new MetricsListener(new KMSService(), config);
429-
await metricsListener.onStartInvocation(undefined);
430-
if (config.enhancedMetrics) {
431-
incrementErrorsMetric(metricsListener);
432-
}
433-
434427
if (getEnvValue("DD_TRACE_ENABLED", "true").toLowerCase() === "true") {
435428
const options: SpanOptions = {
436429
tags: {
@@ -451,5 +444,11 @@ export async function emitTelemetryOnErrorOutsideHandler(
451444
span.finish();
452445
}
453446

447+
const config = getConfig();
448+
const metricsListener = new MetricsListener(new KMSService(), config);
449+
await metricsListener.onStartInvocation(undefined);
450+
if (config.enhancedMetrics) {
451+
incrementErrorsMetric(metricsListener);
452+
}
454453
await metricsListener.onCompleteInvocation();
455454
}

0 commit comments

Comments
 (0)