From 930eba914a9f380c9dd943d3a8aa33a3230ed650 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:26:49 +0530 Subject: [PATCH] Update Metric.scala --- .../sttp/tapir/server/metrics/Metric.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala b/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala index 8c90e9fb3b..05bb9762ed 100644 --- a/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala +++ b/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala @@ -64,3 +64,22 @@ object MetricLabels { ) ) } + +object OTELMetricLabels { + + /** Labels request by path and http.request.method, response by http.response.status_code */ + lazy val Default: MetricLabels = MetricLabels( + forRequest = List( + "http.request.method" -> { case (_, req) => req.method.method }, + "path" -> { case (ep, _) => ep.showPathTemplate(showQueryParam = None) } + ), + forResponse = List( + "http.response.status_code" -> { + // OpenTelemetry-compliant + case Right(r) => r.code.code.toString + // Default to 500 for exceptions + case Left(_) => "500" + } + ) + ) +}