From e5cc05917dbb6db21ac00d10e2985f81b6d44c77 Mon Sep 17 00:00:00 2001 From: Michael Nedokushev Date: Wed, 7 Jun 2023 22:29:08 +0100 Subject: [PATCH] OpenTelemetry: improve instrumentation example --- .../example/http/HttpServerApp.scala | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/opentelemetry-instrumentation-example/src/main/scala/zio/telemetry/opentelemetry/instrumentation/example/http/HttpServerApp.scala b/opentelemetry-instrumentation-example/src/main/scala/zio/telemetry/opentelemetry/instrumentation/example/http/HttpServerApp.scala index 52af5f45..f79fbeed 100644 --- a/opentelemetry-instrumentation-example/src/main/scala/zio/telemetry/opentelemetry/instrumentation/example/http/HttpServerApp.scala +++ b/opentelemetry-instrumentation-example/src/main/scala/zio/telemetry/opentelemetry/instrumentation/example/http/HttpServerApp.scala @@ -10,15 +10,25 @@ case class HttpServerApp(tracing: Tracing) { val routes: HttpApp[Any, Throwable] = Http.collectZIO { case _ @Method.GET -> _ / "health" => - health @@ span("health-endpoint") + for { + _ <- serverSpan + _ <- healthSpan @@ span("health span") + response <- ZIO.succeed(Response.ok) + } yield response + } - def health: UIO[Response] = + private def serverSpan: UIO[Unit] = + for { + _ <- tracing.setAttribute("zio", true) + _ <- tracing.addEvent("running server span") + } yield () + + private def healthSpan: UIO[Unit] = for { - _ <- tracing.addEvent("executing health logic") - _ <- tracing.setAttribute("zio", "telemetry") - response <- ZIO.succeed(Response.ok) - } yield response + _ <- tracing.addEvent("executing health logic") + _ <- tracing.setAttribute("zio", "telemetry") + } yield () }