Skip to content

Commit

Permalink
Update metrics/opentelemetry-metrics/src/main/scala/sttp/tapir/server…
Browse files Browse the repository at this point in the history
…/metrics/opentelemetry/OpenTelemetryMetrics.scala
  • Loading branch information
varshith257 authored Nov 16, 2024
1 parent 966631c commit 21d174f
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ object OpenTelemetryMetrics {
"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"
"http.response.status_code" -> { response: Either[Throwable, ServerResponse[_]] =>
response match {
case Right(r) => r.code.code.toString
// Default to 500 for exceptions
case Left(_) => "500"
}
},
"error.type" -> {
case Left(ex) => Some(ex.getClass.getName) // Exception class name for pre-response errors
case Right(_) => None // No error.type for successful responses
"error.type" -> { response: Either[Throwable, ServerResponse[_]] =>
response match {
case Left(ex) => Some(ex.getClass.getName) // Exception class name for pre-response errors
case Right(_) => None // No error.type for successful responses
}
}
).collect { case (k, Some(v)) => k -> v }
).collect { case (k, v) if v(response) != None => k -> v(response).get }
)

def apply[F[_]](meter: Meter): OpenTelemetryMetrics[F] = apply(meter, Nil)
Expand Down

0 comments on commit 21d174f

Please sign in to comment.