Skip to content

Commit

Permalink
Update Metric.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 authored Nov 3, 2024
1 parent 354afd5 commit 00f153d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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 @@ -63,4 +63,25 @@ object MetricLabels {
}
)
)

/** Default labels for OpenTelemetry-compliant metrics, as recommended here:
* https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-server
*
* - `http.request.method` - HTTP request method (e.g., GET, POST).
* - `path` - The request path or route template.
* - `http.response.status_code` - HTTP response status code (200, 404, etc.).
*/
lazy val OpenTelemetryAttributes: 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" -> {
case Right(r) => r.code.code.toString
// Default to 500 for exceptions
case Left(_) => "500"
}
)
)
}

0 comments on commit 00f153d

Please sign in to comment.