Skip to content

Commit

Permalink
create new metric handler duration
Browse files Browse the repository at this point in the history
  • Loading branch information
zi-yang-uni committed Sep 5, 2024
1 parent 22b0f71 commit 0494e45
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/entities/aws-metrics-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export enum Metric {
QUOTE_REQUESTED = 'QUOTE_REQUESTED',
QUOTE_LATENCY = 'QUOTE_LATENCY',
QUOTE_RESPONSE_COUNT = 'QUOTE_RESPONSE_COUNT',
HANDLER_DURATION = 'HANDLER_DURATION',

QUOTE_POST_ERROR = 'QUOTE_POST_ERROR',
QUOTE_POST_ATTEMPT = 'QUOTE_POST_ATTEMPT',
Expand Down
5 changes: 3 additions & 2 deletions lib/handlers/base/api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export abstract class APIGLambdaHandler<
const response = await handler(event, context);
const requestEnd = new Date().getTime();

// Track latency
metric.putMetric(Metric.QUOTE_LATENCY, requestEnd - requestStart, MetricLoggerUnit.Milliseconds);
// Track handler duration
metric.putDimensions({ HandlerName: this.handlerName });
metric.putMetric(Metric.HANDLER_DURATION, requestEnd - requestStart, MetricLoggerUnit.Milliseconds);

return {
...response,
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class QuoteHandler extends APIGLambdaHandler<
});
if (response.statusCode == 200 || response.statusCode == 201) {
metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count);
metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds);
const hardResponse = new HardQuoteResponse(request, cosignedOrder);
if (!bestQuote) {
// The RFQ responses are logged in getBestQuote()
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class QuoteHandler extends APIGLambdaHandler<
log.info({ bestQuote: bestQuote }, 'bestQuote');

metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count);
metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds);
return {
statusCode: 200,
body: bestQuote.toResponseJSON(),
Expand Down

0 comments on commit 0494e45

Please sign in to comment.