Skip to content

Commit

Permalink
Update OpenTelemetryMetrics.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 authored Nov 28, 2024
1 parent 7c0ba2a commit c6b38ec
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ object OpenTelemetryMetrics {
"url.scheme" -> { case (_, req) => req.uri.scheme.getOrElse("unknown") },
"path" -> { case (ep, _) => ep.showPathTemplate(showQueryParam = None) }
),
forResponse = {
List[(String, Either[Throwable, ServerResponse[_]] => Option[String])](
"http.response.status_code" -> {
case Right(r) => Some(r.code.code.toString)
// Default to 500 for exceptions
case Left(_) => Some("500")
},
"error.type" -> {
case Left(ex) => Some(ex.getClass.getName) // Exception class name for errors
case Right(_) => None // No error.type for successful responses
}
).collect { case (k, fn) => k -> fn } // Keep functions intact for attributes
}
forResponse = List(
"http.response.status_code" -> {
case Right(r) => Some(r.code.code.toString)
// Default to 500 for exceptions
case Left(_) => Some("500")
},
"error.type" -> {
case Left(ex) => Some(ex.getClass.getName) // Exception class name for errors
case Right(_) => None // No error.type for successful responses
}
)
)

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

0 comments on commit c6b38ec

Please sign in to comment.