Skip to content

Commit

Permalink
Merge pull request #590 from iRevive/docs/noop-tracer
Browse files Browse the repository at this point in the history
Docs: separate Scala 2 / Scala 3 examples of the no-op tracer
  • Loading branch information
iRevive authored Apr 16, 2024
2 parents 9cdf8b4 + b151c70 commit 6358c42
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Expand Down
54 changes: 50 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6358c42

Please sign in to comment.