Skip to content

Commit

Permalink
Update Metric.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 authored Oct 30, 2024
1 parent 6d5dd85 commit 930eba9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
)
)
}

0 comments on commit 930eba9

Please sign in to comment.