From b151c7005d16340b6178cf2cfc5673c5af953ba7 Mon Sep 17 00:00:00 2001 From: Maksym Ochenashko Date: Wed, 10 Apr 2024 10:09:46 +0300 Subject: [PATCH] Docs: separate Scala 2 / Scala 3 examples of the no-op tracer --- build.sbt | 5 +++++ docs/index.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 8bddfbdd2..7c8d35496 100644 --- a/build.sbt +++ b/build.sbt @@ -609,6 +609,11 @@ lazy val docs = project ChoiceConfig("sbt", "sbt"), ChoiceConfig("scala-cli", "Scala CLI"), ChoiceConfig("shell", "Shell") + ).withSeparateEbooks, + SelectionConfig( + "scala-version", + ChoiceConfig("scala-2", "Scala 2"), + ChoiceConfig("scala-3", "Scala 3") ).withSeparateEbooks ) ) diff --git a/docs/index.md b/docs/index.md index 0796f8aff..76fc782d7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -83,16 +83,62 @@ Add directives to the `*.scala` file: If you use a library that supports otel4s (eg [Skunk](https://github.com/typelevel/skunk)) but do not want to use Open Telemetry, then you can place the [No-op Tracer](https://www.javadoc.io/doc/org.typelevel/otel4s-docs_2.13/latest/org/typelevel/otel4s/trace/Tracer$.html) into implicit scope. -```scala mdoc:silent -// via import -// import org.typelevel.otel4s.trace.Tracer.Implicits.noop +The no-op `Tracer` can be provided in the following ways: -// via implicit val +@:select(scala-version) + +@:choice(scala-2) + +By using the `import Tracer.Implicits.noop`: +```scala mdoc:compile-only +import cats.effect.IO +import org.typelevel.otel4s.trace.Tracer + +def program[F[_]: Tracer]: F[Unit] = ??? + +import Tracer.Implicits.noop +val io: IO[Unit] = program[IO] +``` + +By defining an `implicit val`: + +```scala mdoc:compile-only import cats.effect.IO import org.typelevel.otel4s.trace.Tracer + +def program[F[_]: Tracer]: F[Unit] = ??? + implicit val tracer: Tracer[IO] = Tracer.noop +val io: IO[Unit] = program[IO] ``` +@:choice(scala-3) + +By using the `import Tracer.Implicits.noop`: +```dotty +import cats.effect.IO +import org.typelevel.otel4s.trace.Tracer + +def program[F[_]](using Tracer[F]): F[Unit] = ??? + +import Tracer.Implicits.noop +val io: IO[Unit] = program[IO] +``` + +By defining a `given`: + +```dotty +import cats.effect.IO +import org.typelevel.otel4s.trace.Tracer + +def program[F[_]](using Tracer[F]): F[Unit] = ??? + +given Tracer[IO] = Tracer.noop +val io: IO[Unit] = program[IO] +``` + +@:@ + [cats-effect]: https://typelevel.org/cats-effect/ [opentelemetry-java]: https://github.com/open-telemetry/opentelemetry-java/tree/main/api/all [opentelemetry-java-autoconfigure]: https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md