From 4c8623ab498658f4c864644eb0524b9e54388a33 Mon Sep 17 00:00:00 2001 From: Miguel Cervera Date: Thu, 8 Jun 2023 12:02:28 -0700 Subject: [PATCH] Log request metric in the finally block (#222) * Log request metric in the finally block * also log latency on the finally block --- lib/handlers/quote/quote.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/handlers/quote/quote.ts b/lib/handlers/quote/quote.ts index fb57a574c3..d2ed7d9ebf 100644 --- a/lib/handlers/quote/quote.ts +++ b/lib/handlers/quote/quote.ts @@ -51,9 +51,6 @@ export class QuoteHandler extends APIGLambdaHandler< try { result = await this.handleRequestInternal(params) - // This metric is logged after calling the internal handler to correlate with the status metrics - metric.putMetric(`GET_QUOTE_REQUESTED_CHAINID: ${chainId}`, 1, MetricLoggerUnit.Count) - switch (result.statusCode) { case 200: case 202: @@ -74,11 +71,12 @@ export class QuoteHandler extends APIGLambdaHandler< metric.putMetric(`GET_QUOTE_500_CHAINID: ${chainId}`, 1, MetricLoggerUnit.Count) throw err - } + } finally { + // This metric is logged after calling the internal handler to correlate with the status metrics + metric.putMetric(`GET_QUOTE_REQUESTED_CHAINID: ${chainId}`, 1, MetricLoggerUnit.Count) - // We have to log the requested metric here, since a failure would take us out of the normal execution flow - metric.putMetric(`GET_QUOTE_REQUESTED_CHAINID: ${chainId}`, 1, MetricLoggerUnit.Count) - metric.putMetric(`GET_QUOTE_LATENCY_CHAIN_${chainId}`, Date.now() - startTime, MetricLoggerUnit.Milliseconds) + metric.putMetric(`GET_QUOTE_LATENCY_CHAIN_${chainId}`, Date.now() - startTime, MetricLoggerUnit.Milliseconds) + } return result }