typelevel / otel4s-experimental   0.2.0

Apache License 2.0 GitHub
Scala versions: 3.x 2.13
Scala.js versions: 1.x
Scala Native versions: 0.4


Typelevel Organization Project Maven Central


The otel4s-experimental project provides no binary compatibility guarantees between releases. Changes made in this repository may be completely incompatible with previous versions.

otel4s-experimental is a companion project for the otel4s. The key points of the repository:

  • Develop and test new experimental features
  • Provide access to the unstable functionality without breaking the otel4s
  • Some features may be upstreamed to the otel4s eventually

Metrics - getting started

Add the otel4s-experimental-metrics dependency to the build.sbt:

libraryDependencies ++= Seq(
  "org.typelevel" %% "otel4s-experimental-metrics" % "<version>"

1) IOMetrics - cats-effect runtime metrics

import cats.effect.{IO, IOApp}
import org.typelevel.otel4s.experimental.metrics._
import org.typelevel.otel4s.oteljava.OtelJava

object Main extends IOApp.Simple {
  def app: IO[Unit] = ???

  def run: IO[Unit] =
    OtelJava.autoConfigured[IO]().use { otel4s =>
      otel4s.meterProvider.get("service.meter").flatMap { implicit meter =>

The metrics can be visualized in Grafana using this dashboard.

Trace - getting started

Add the otel4s-experimental-trace dependency to the build.sbt:

libraryDependencies ++= Seq(
  "org.typelevel" %%% "otel4s-experimental-trace" % "<version>"

1) @span annotation

The body of a method annotated with @span will be wrapped into a span:

import org.typelevel.otel4s.experimental.{attribute, span}

def findUser(
  @attribute userId: Long, 
  @attribute("user.hash") hash: String
): F[User] = ???

// expands into

def findUser(
    userId: Long, 
    hash: String
): F[User] = 
    Attribute("userId", userId), Attribute("user.hash", hash)

The macro works with variables too:

val findUser: IO[User] = ???

// expands into

val findUser: IO[User] =