From 71ce04ec68ea0ac7c1ab909d0c610fa1bc8fbf22 Mon Sep 17 00:00:00 2001 From: Pierre Ricadat Date: Fri, 12 Jan 2024 10:20:04 +0900 Subject: [PATCH] [OpenTracing] Preserve Throwable failures when logging errors --- .../zio/telemetry/opentracing/OpenTracing.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/opentracing/src/main/scala/zio/telemetry/opentracing/OpenTracing.scala b/opentracing/src/main/scala/zio/telemetry/opentracing/OpenTracing.scala index f000fe45..33202aa5 100644 --- a/opentracing/src/main/scala/zio/telemetry/opentracing/OpenTracing.scala +++ b/opentracing/src/main/scala/zio/telemetry/opentracing/OpenTracing.scala @@ -125,10 +125,14 @@ object OpenTracing { logError: Boolean = true )(implicit trace: Trace): UIO[Unit] = for { - _ <- ZIO.succeed(span.setTag("error", true)).when(tagError) - _ <- ZIO - .succeed(span.log(Map("error.object" -> FiberFailure(cause), "stack" -> cause.prettyPrint).asJava)) - .when(logError) + _ <- ZIO.succeed(span.setTag("error", true)).when(tagError) + throwable = cause.failureOption match { + case Some(t: Throwable) => t + case _ => FiberFailure(cause) + } + _ <- ZIO + .succeed(span.log(Map("error.object" -> throwable, "stack" -> cause.prettyPrint).asJava)) + .when(logError) } yield () override def finish(span: Span)(implicit trace: Trace): UIO[Unit] =