Skip to content

Commit

Permalink
Update OpenTelemetryMetrics.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 authored Dec 11, 2024
1 parent a3ebd6c commit eec5498
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ object OpenTelemetryMetrics {
),
forResponse = List(
"http.response.status_code" -> {
case Right(r) => r.code.code.toString
case Right(r) => Some(r.code.code.toString)
// Default to 500 for exceptions
case Left(_) => "500"
case Left(_) => Some("500")
},
"error.type" -> {
case Left(ex) => ex.getClass.getName // Exception class name for errors
case Right(_) => ""
case Left(ex) => Some(ex.getClass.getName) // Exception class name for errors
case Right(_) => None
}
)
)
Expand Down Expand Up @@ -199,8 +199,7 @@ object OpenTelemetryMetrics {
private def asOpenTelemetryAttributes(l: MetricLabels, res: Either[Throwable, ServerResponse[_]], phase: Option[String]): Attributes = {
val builder = Attributes.builder()
l.forResponse.foreach { case (key, valueFn) =>
val value = valueFn(res)
if (value.nonEmpty) builder.put(key, value)
valueFn(res).foreach(value => builder.put(key, value))
}
phase.foreach(v => builder.put(l.forResponsePhase.name, v))
builder.build()
Expand Down

0 comments on commit eec5498

Please sign in to comment.