Skip to content

Commit

Permalink
add missing await and move metrics block
Browse files Browse the repository at this point in the history
  • Loading branch information
TalUsvyatsky committed May 7, 2024
1 parent 02e9ae7 commit 050662c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/handler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let wrapped_handler;
try {
wrapped_handler = datadog(await load(taskRootEnv, handlerEnv), { traceExtractor });
} catch (error) {
emitTelemetryOnErrorOutsideHandler(error, handlerEnv, Date.now());
await emitTelemetryOnErrorOutsideHandler(error, handlerEnv, Date.now());
throw error;
}

Expand Down
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,6 @@ export async function emitTelemetryOnErrorOutsideHandler(
functionName: string,
startTime: number,
): Promise<void> {
const config = getConfig();
const metricsListener = new MetricsListener(new KMSService(), config);
await metricsListener.onStartInvocation(undefined);
if (config.enhancedMetrics) {
incrementErrorsMetric(metricsListener);
}

if (getEnvValue("DD_TRACE_ENABLED", "true").toLowerCase() === "true") {
const options: SpanOptions = {
tags: {
Expand All @@ -451,5 +444,11 @@ export async function emitTelemetryOnErrorOutsideHandler(
span.finish();
}

const config = getConfig();
const metricsListener = new MetricsListener(new KMSService(), config);
await metricsListener.onStartInvocation(undefined);
if (config.enhancedMetrics) {
incrementErrorsMetric(metricsListener);
}
await metricsListener.onCompleteInvocation();
}

0 comments on commit 050662c

Please sign in to comment.