Releases: typelevel/otel4s
v0.14.0-RC2
What's Changed
OtelJava
- unwrap IOLocalContextStorage from SettableContextStorageProvider in t… by @AlixBa in #996
- add fromInMemory on Testkits by @AlixBa in #1081
Documentation
Dependencies
- Update opentelemetry-javaagent to 2.20.0 by @typelevel-steward[bot] in #1080
- Update opentelemetry-instrumentation-annotations to 2.20.0 by @typelevel-steward[bot] in #1079
Uncategorized
Full Changelog: v0.14.0-RC1...v0.14.0-RC2
v0.14.0-RC1
We are happy to announce the first candidate of the 0.14.0 release.
Warning
While most changes are source-compatible, there are a few binary-breaking changes across multiple modules.
Please review carefully before upgrading.
Key changes
1. Sealed interfaces
We have sealed many of the core interfaces. There are two sides of this decision:
- Cons: This makes it harder for third-party libraries to extend otel4s directly.
- Pros: It gives us much more flexibility to evolve the public API safely over time.
This change is especially important as we look ahead to the 1.0 release.
The OpenTelemetry specification is still actively evolving, and sealing interfaces allows us to add new methods without breaking binary compatibility.
We know this is a trade-off. If feedback shows this experiment is not working well, we may unseal some interfaces in the future.
See the reasoning behind this change: #1029.
2. Attributes.Make
We have introduced the Attributes.Make
typeclass to make it easier to turn your own domain values into Attributes
.
For example:
case class User(id: Long, group: String)
implicit val userAttributesMake: Attributes.Make[User] =
user => Attributes(Attribute("user.id", user.id), Attribute("user.group", user.group))
// now you can directly create attributes from your User
val attributes: Attributes = Attributes.from(User(1L, "admin"))
// use it naturally in spans:
Tracer[IO].span("find-user", Attributes.from(user))
This is especially useful when you want to consistently record attributes for domain entities such as users, orders, sessions, or request metadata.
3. mapK
renamed to liftTo
As preparation for #1001, all mapK
methods have been renamed to liftTo
.
The change is binary-compatible. Old usages still compile, but you will see a deprecation warning pointing you to the new liftTo method.
This should make migrations smooth.
4. New Logging
module
Note
The logging module only for bridging logs from other logging frameworks into OpenTelemetry.
It is not a replacement for a full logging API.
We now provide an experimental logging module:
- Spec: https://opentelemetry.io/docs/specs/otel/logs/
- Modules:
otel4s-logs
,otel4s-oteljava-logs
,otel4s-sdk-logs
,otel4s-sdk-exporter-logs
Examples:
- A library such as scribe or log4cats can use the
otel4s-logs
API to export logs over the OpenTelemetry protocol. - OpenTelemetry-Java bindings are provided in
otel4s-oteljava-logs
. - For Scala.js and Scala Native,
otel4s-sdk-logs
offers a pure Scala implementation.
This closes an important gap in the ecosystem, allowing structured logs to be exported alongside metrics and traces.
Acknowledgements
Big thanks to @NthPortal for thorough reviews and valuable feedback during this cycle. 🙌
What's Changed
Core
- logs: add
core-logs
module by @iRevive in #1013 - core-common: add
AnyValue
by @iRevive in #1009 - core-logs: add Severity by @iRevive in #1015
- Define
hashCode
aslazy val
by @c0d33ngr in #1019 - core-common: add
Attributes.Make
by @iRevive in #1023 - core-logs: add LogRecordBuilder by @iRevive in #1018
- docs: update scaladoc example by @iRevive in #1034
- core-logs: add
LoggerProvider
,LoggerBuilder
, andLogger
by @iRevive in #1030 - Rename most
mapK
methods toliftTo
by @NthPortal in #1002 - Seal public traits by @iRevive in #1037
- sdk-exporter-logs: add
LogsProtoEncoder
by @iRevive in #1057 - Add
otel4s-oteljava-logs
module by @iRevive in #1038 - Wire all logs modules together by @iRevive in #1077
SDK
- sdk-logs: add
LogRecordData
by @iRevive in #1040 - sdk-logs: add
LogRecordLimits
by @iRevive in #1041 - sdk-logs: add
LogRecordLimitsAutoConfigure
by @iRevive in #1058 - sdk-logs: add
LogRecordExporter
by @iRevive in #1056 - sdk-logs: add
ConsoleLogRecordExporter
by @iRevive in #1061 - sdk-logs: add
LogRecordProcessor
by @iRevive in #1055 - sdk-logs: Evaluate multiple processors sequentially by @iRevive in #1068
- sdk-logs: Add
SimpleLogRecordProcessor
by @iRevive in #1067 - sdk-logs: Add
BatchLogRecordProcessor
by @iRevive in #1066 - sdk-logs: Add
SdkLogRecordBuilder
by @iRevive in #1069 - sdk-logs: Add
LogRecordExportersAutoConfigure
by @iRevive in #1071 - sdk-logs: Add
SdkLoggerProvider
,SdkLoggerBuilder
, andSdkLogger
by @iRevive in #1072 - sdk-logs-testkit: Add
LogsTestkit
by @iRevive in #1070 - sdk-logs: add
BatchLogRecordProcessorAutoConfigure
by @iRevive in #1073 - sdk-logs: add
LoggerProviderAutoConfigurer
by @iRevive in #1075 - sdk-logs: add
SdkLogs
by @iRevive in #1076 - Add
otel4s-sdk-logs
module by @iRevive in #1039
SDK exporter
- sdk-exporter: update OTLP exporter docs by @iRevive in #1042
- sdk-exporter-logs: add
OtlpLogRecordExporter
by @iRevive in #1063
Semantic Conventions
OtelJava
- oteljava: add
TracesTestkit#resetSpans
by @iRevive in #1028 - oteljava-logs-test: add
LogsTestkit
by @iRevive in #1064
Documentation
- docs: add sttp and tapir to the ecosystem by @iRevive in #1024
- Use Resource.fromAutoCloseable in docs by @mzuehlke in #1033
- docs: add otel4s Java Agent example by @iRevive in #1044
Dependencies
- Update cats-effect, cats-effect-kernel, ... to 3.6.3 by @typelevel-steward[bot] in #1022
- Update opentelemetry-instrumentation-annotations to 2.19.0 by @typelevel-steward[bot] in #1045
- Update opentelemetry-javaagent to 2.19.0 by @typelevel-steward[bot] in #1046
- Update opentelemetry-semconv to 1.37.0 by @typelevel-steward[bot] in #1051
- flake.lock: Update by @typelevel-steward[bot] in #1052
- Update opentelemetry-proto to 1.8.0-alpha by @typelevel-steward[bot] in #1054
- Update pekko-stream to 1.2.0 by @typelevel-steward[bot] in #1053
- Update fs2-core, fs2-io, fs2-scodec to 3.12.2 by @typelevel-steward[bot] in #1060
- Update opentelemetry-api, ... to 1.54.0 by @typelevel-steward[bot] in #1062
- Update sbt, scripted-plugin to 1.11.6 by @typelevel-steward[bot] in #1065
New Contributors
Full Changelog: v0.13.1...v0.14.0-RC1
v0.13.1
What's Changed
SDK
Documentation
Dependencies
- flake.lock: Update by @typelevel-steward in #1004
- Update opentelemetry-instrumentation-annotations to 2.17.0 by @typelevel-steward in #1003
- Update sbt, scripted-plugin to 1.11.3 by @typelevel-steward in #1005
- Update cats-effect, cats-effect-kernel, ... to 3.6.2 by @typelevel-steward in #1006
Full Changelog: v0.13.0...v0.13.1
v0.13.0
We are happy to announce the 0.13.0 release. It brings some UX improvements and new features.
Warning
There are several binary breaking changes core and sdk modules.
New features
1. Redesigned BaggageManager
The BaggageManager
no longer extends the cats.mtl.Local
. Some methods are deprecated to ease the migration.
2. Dynamic InstrumentMeta
The change introduces two implementations of InstrumentMeta
to align with OpenTelemetry's specification, allowing instruments to reflect their enabled or disabled status dynamically.
InstrumentMeta.Dynamic
uses an effectful F[Boolean]
for runtime checks, while InstrumentMeta.Static
retains a fixed Boolean
for simpler cases like Span
.
What's Changed
Core
- Fix
KindTransformer
instances by @NthPortal in #979 - Redesign
BaggageManager
by @NthPortal in #974 - trace: make SpanBuilder stack safe by @iRevive in #990
- Dynamic instrument meta (enabled/disabled status) by @iRevive in #963
SDK
- SpanBuilder: chain modifyState functions by @iRevive in #965
- sdk: move
LimitedData
to sdk-common by @iRevive in #992 - sdk-trace: use
TracerProvider.noop
when span processors aren't configured by @iRevive in #991 - sdk: move
TraceContext
to sdk-common by @iRevive in #993 - Allocate noop meter instruments only once by @AlixBa in #977
Semantic Conventions
- Update opentelemetry-semconv to 1.34.0 by @typelevel-steward in #988
Dependencies
- Update munit-cats-effect to 2.1.0 by @typelevel-steward in #952
- Update cats-effect, cats-effect-kernel, ... to 3.6.1 by @typelevel-steward in #956
- Update scala3-library, ... to 3.3.6 by @typelevel-steward in #966
- Update pekko-http to 1.2.0 by @typelevel-steward in #972
- Update opentelemetry-instrumentation-annotations to 2.16.0 by @typelevel-steward in #970
- Update opentelemetry-javaagent to 2.16.0 by @typelevel-steward in #971
- Update opentelemetry-proto to 1.7.0-alpha by @typelevel-steward in #975
- Update opentelemetry-api, ... to 1.51.0 by @typelevel-steward in #985
- flake.lock: Update by @typelevel-steward in #978
- Update sbt-typelevel, ... to 0.8.0 by @typelevel-steward in #981
- Update sbt, scripted-plugin to 1.11.2 by @typelevel-steward in #987
- Update sbt-protoc to 1.0.8 by @typelevel-steward in #984
- Update pekko-stream to 1.1.4 by @typelevel-steward in #989
Uncategorized
Full Changelog: v0.12.0...v0.13.0
v0.12.0
We are happy to announce the 0.12.0 release. It brings some UX improvements and new features.
Warning
There are multiple binary breaking changes across modules.
This version relies on new functionality from Cats Effect 3.6.0, such as IORuntimeMetrics
.
New features
1. BaggageManager
BaggageManager
is a functional abstraction that provides an interface to manage Baggage
.
Documentation: https://typelevel.org/otel4s/instrumentation/baggage.html
Reading the current Baggage:
import org.typelevel.otel4s.baggage.{Baggage, BaggageManager}
def printBaggage(implicit bm: BaggageManager[IO]): IO[Unit] =
BaggageManager[IO].current.flatMap(b => IO.println(s"Baggage: $b"))
Setting and modifying Baggage
def withUserId[A](fa: IO[A])(implicit bm: BaggageManager[IO]): IO[A] =
bm.local(fa)(b => b.updated("user-id", "12345"))
def withScopedBaggage[A](fa: IO[A])(implicit bm: BaggageManager[IO]): IO[A] =
bm.scope(fa)(Baggage.empty.updated("request-id", "req-abc"))
Retrieving a specific baggage entry
def fetchBaggageEntry(implicit bm: BaggageManager[IO]): IO[Unit] =
bm.getValue("user-id").flatMap {
case Some(userId) => IO.println(s"User ID: $userId")
case None => IO.println("User ID not found in baggage")
}
2. Attribute.From
Allows creating an attribute value from an arbitrary type:
case class UserId(id: Int)
implicit val userIdFrom: Attribute.From[UserId, Long] =
_.id.toLong
val userIdKey = AttributeKey[Long]("user.id")
val attribute: Attribute[Long] = userIdKey(UserId(1))
val attribute: Attribute[Long] = Attribute.from(userIdKey, UserId(1))
val attribute: Attribute[Long] = Attribute.from("user.id", UserId(1))
3. Attribute.Make
Allows creating an attribute from an arbitrary type:
case class UserId(id: Int)
implicit val userIdFrom: Attribute.From[UserId, Long] =
_.id.toLong
implicit val userIdMake: Attribute.Make[UserId, Long] =
Attribute.Make.const("user.id")
// "user.id=1"
val attribute: Attribute[Long] = Attribute.from(UserId(1))
Before:
def findUser(userId: UserId): F[Unit] =
Tracer[F].span("findUser", Attribute("user.id", userId.id.toLong))
After:
def findUser(userId: UserId): F[Unit] =
Tracer[F].span("findUser", Attribute.from(userId))
4. Cats Effect IO Runtime metrics
Documentation: https://typelevel.org/otel4s/instrumentation/metrics-cats-effect-io-runtime.html.
Configure the build.sbt
:
libraryDependencies ++= Seq(
"org.typelevel" %%% "otel4s-instrumentation-metrics" % "0.12.0"
)
Use IORuntimeMetrics.register
to register collectors:
import cats.effect._
import org.typelevel.otel4s.instrumentation.ce.IORuntimeMetrics
import org.typelevel.otel4s.metrics.MeterProvider
import org.typelevel.otel4s.trace.TracerProvider
import org.typelevel.otel4s.oteljava.OtelJava
object Main extends IOApp.Simple {
def run: IO[Unit] =
OtelJava.autoConfigured[IO]().use { otel4s =>
implicit val mp: MeterProvider[IO] = otel4s.meterProvider
IORuntimeMetrics
.register[IO](runtime.metrics, IORuntimeMetrics.Config.default)
.surround {
program(otel4s.meterProvider, otel4s.tracerProvider)
}
}
def program(
meterProvider: MeterProvider[IO],
tracerProvider: TracerProvider[IO]
): IO[Unit] = {
val _ = (meterProvider, tracerProvider)
IO.unit
}
}
5. OtelJava: seamless context propagation between IO and OpenTelemetry Java SDK
Warning
The IOLocalContextStorageProvider
doesn't work with OpenTelemetry Java Agent yet.
Documentation: https://typelevel.org/otel4s/oteljava/tracing-context-propagation.html.
Configure the build.sbt
:
libraryDependencies ++= Seq(
"org.typelevel" %% "otel4s-oteljava" % "0.12.0",
"org.typelevel" %% "otel4s-oteljava-context-storage" % "0.12.0",
)
javaOptions += "-Dcats.effect.trackFiberContext=true"
Use IOLocalContextStorage.localProvider
as a LocalProvider
:
import cats.effect.IO
import io.opentelemetry.api.trace.{Span => JSpan}
import org.typelevel.otel4s.context.LocalProvider
import org.typelevel.otel4s.oteljava.IOLocalContextStorage
import org.typelevel.otel4s.oteljava.OtelJava
import org.typelevel.otel4s.oteljava.context.Context
import org.typelevel.otel4s.trace.Tracer
def program(tracer: Tracer[IO]): IO[Unit] =
tracer.span("test").use { span => // start 'test' span using otel4s
println(s"jctx: ${JSpan.current().getSpanContext}") // get a span from a ThreadLocal var
IO.println(s"otel4s: ${span.context}")
}
def run: IO[Unit] = {
implicit val provider: LocalProvider[IO, Context] =
IOLocalContextStorage.localProvider[IO]
OtelJava.autoConfigured[IO]().use { otelJava =>
otelJava.tracerProvider.tracer("com.service").get.flatMap { tracer =>
program(tracer)
}
}
}
What's Changed
Core
- core-common: remove public
localForIOLocal
instance by @iRevive in #868 - Add
IORuntimeMetrics
by @iRevive in #861 - Add
IOLocalContextStorage
by @rossabaker in #214 - Update scalafmt-core to 3.8.5 by @typelevel-steward in #892
- Fix copy/paste errors in docs by @NthPortal in #904
- Add implicit
Otel4s#localContext
by @NthPortal in #907 - core-common: redefine
Attribute
as a sealed trait by @iRevive in #906 - Add
BaggageManager
utility by @NthPortal in #908 - docs: add
Baggage
example by @iRevive in #915 - core-common: add
Attribute.from
by @iRevive in #911 - docs: update
SpanOps#resource
documentation by @iRevive in #924 - core-common: add
Attribute.Make
by @iRevive in #916 - Add implicit
Attribute.From
instances by @NthPortal in #926
SDK
- sdk: refactor SpanProcessor by @iRevive in #856
- Update cats-effect to
3.6.0-RC1
, resolve compilation issues by @iRevive in #866 - Use
MapRef.apply
by @iRevive in #880 - Use
SystemProperties
by @iRevive in #882 - sdk: propagate
Env
by @iRevive in #883 - sdk-common: rename
otel.experimental.resource.disabled.keys
tootel.resource.disabled.keys
by @iRevive in #889 - Add
sdk.Context#getOrElse
by @NthPortal in #909 - Update opentelemetry-semconv to 1.30.0 by @typelevel-steward in #922
- sdk-trace: remove
exception.escaped
attribute by @iRevive in #923
SDK exporter
- sdk-exporter: generate proto models in the private package by @iRevive in #860
- Update fs2 to
3.12.0-RC1
, removeepollcat
by @iRevive in #884
Semantic Conventions
- Update opentelemetry-semconv to 1.29.0-alpha by @typelevel-steward in #869
OtelJava
- oteljava: refactor Metrics, Traces, and OtelJava API by @iRevive in #867
- oteljava: move
IOLocalContextStorage
to thecontext
package by @iRevive in #879 - Allow instrumentation via OTeL Java Agent by @iRevive in #944
- oteljava-context-storage: update agent instrumentation direction by @iRevive in #948
Documentation
- docs: simplified docker setup with otel-lgtm image by @AlixBa in #871
- Minor documentation tweaks by @iRevive in #877
- docs: add Grafana dashboard link by @iRevive in #878
- Update ecosystem.md: mention otel4s-doobie by @arturaz in #901
Other
- Aggregate
oteljava
project by @iRevive in #881 - instrumentation-metrics: fix poller metrics by @iRevive in #945
Dependencies
- Update http4s-circe, http4s-dsl, ... to 0.23.30 by @typelevel-steward in #863
- Update opentelemetry-proto to 1.5.0-alpha by @typelevel-steward in #886
- Update pekko-stream to 1.1.3 by @typelevel-steward in #887
- Update scala-library, scala-reflect to 2.13.16 by @typelevel-steward in #891
- Update sbt-typelevel, ... to 0.7.7 by @typelevel-steward in #900
- Update sbt-scalajs, scalajs-compiler, ... to 1.18.2 by @typelevel-steward in #898
- Update scala3-library, ... to 3.3.5 by @typelevel-steward in #905
- Update cats-effect, cats-effect-kernel, ... to 3.6.0-RC2 by @typelevel-...
v0.12.0-RC4
What's Changed
OtelJava
Metrics
Dependencies
- flake.lock: Update by @typelevel-steward in #931
- Update scalafmt-core to 3.9.2 by @typelevel-steward in #934
- Update opentelemetry-javaagent to 2.13.3 by @typelevel-steward in #933
- Update opentelemetry-instrumentation-annotations to 2.13.3 by @typelevel-steward in #932
- Update sbt, scripted-plugin to 1.10.10 by @typelevel-steward in #937
- Update scalafmt-core to 3.9.3 by @typelevel-steward in #938
- Update opentelemetry-api, ... to 1.48.0 by @typelevel-steward in #939
- Update sbt, scripted-plugin to 1.10.11 by @typelevel-steward in #943
- Update opentelemetry-javaagent to 2.14.0 by @typelevel-steward in #942
- Update opentelemetry-instrumentation-annotations to 2.14.0 by @typelevel-steward in #941
- Update scalafmt-core to 3.9.4 by @typelevel-steward in #940
- Update fs2-core, fs2-io, fs2-scodec to 3.12.0-RC2 by @typelevel-steward in #946
Full Changelog: v0.12.0-RC3...v0.12.0-RC4
v0.12.0-RC3
New features
1. BaggageManager
BaggageManager
is a functional abstraction that provides an interface to manage Baggage
.
Documentation: https://typelevel.org/otel4s/instrumentation/baggage.html
Reading the current Baggage:
import org.typelevel.otel4s.baggage.{Baggage, BaggageManager}
def printBaggage(implicit bm: BaggageManager[IO]): IO[Unit] =
BaggageManager[IO].current.flatMap(b => IO.println(s"Baggage: $b"))
Setting and modifying Baggage
def withUserId[A](fa: IO[A])(implicit bm: BaggageManager[IO]): IO[A] =
bm.local(fa)(b => b.updated("user-id", "12345"))
def withScopedBaggage[A](fa: IO[A])(implicit bm: BaggageManager[IO]): IO[A] =
bm.scope(fa)(Baggage.empty.updated("request-id", "req-abc"))
Retrieving a specific baggage entry
def fetchBaggageEntry(implicit bm: BaggageManager[IO]): IO[Unit] =
bm.getValue("user-id").flatMap {
case Some(userId) => IO.println(s"User ID: $userId")
case None => IO.println("User ID not found in baggage")
}
2. Attribute.From
Allows creating an attribute value from an arbitrary type:
case class UserId(id: Int)
implicit val userIdFrom: Attribute.From[UserId, Long] =
_.id.toLong
val userIdKey = AttributeKey[Long]("user.id")
val attribute: Attribute[Long] = userIdKey(UserId(1))
val attribute: Attribute[Long] = Attribute.from(userIdKey, UserId(1))
val attribute: Attribute[Long] = Attribute.from("user.id", UserId(1))
3. Attribute.Make
Allows creating an attribute from an arbitrary type:
case class UserId(id: Int)
implicit val userIdFrom: Attribute.From[UserId, Long] =
_.id.toLong
implicit val userIdMake: Attribute.Make[UserId, Long] =
Attribute.Make.const("user.id")
// "user.id=1"
val attribute: Attribute[Long] = Attribute.from(UserId(1))
Before:
def findUser(userId: UserId): F[Unit] =
Tracer[F].span("findUser", Attribute("user.id", userId.id.toLong))
After:
def findUser(userId: UserId): F[Unit] =
Tracer[F].span("findUser", Attribute.from(userId))
What's Changed
Core
- Fix copy/paste errors in docs by @NthPortal in #904
- Add implicit
Otel4s#localContext
by @NthPortal in #907 - core-common: redefine
Attribute
as a sealed trait by @iRevive in #906 - Add
BaggageManager
utility by @NthPortal in #908 - core-common: add
Attribute.from
by @iRevive in #911 - core-common: add
Attribute.Make
by @iRevive in #916 - Add implicit
Attribute.From
instances by @NthPortal in #926
SDK
- sdk-common: rename
otel.experimental.resource.disabled.keys
tootel.resource.disabled.keys
by @iRevive in #889 - Add
sdk.Context#getOrElse
by @NthPortal in #909 - sdk-trace: remove
exception.escaped
attribute by @iRevive in #923
Documentation
- Update ecosystem.md: mention otel4s-doobie by @arturaz in #901
- docs: update
SpanOps#resource
documentation by @iRevive in #924 - docs: add
Baggage
example by @iRevive in #915
Dependencies
- Update opentelemetry-proto to 1.5.0-alpha by @typelevel-steward in #886
- Update pekko-stream to 1.1.3 by @typelevel-steward in #887
- Update sbt-scalajs, scalajs-compiler, ... to 1.18.1 by @typelevel-steward in #897
- Update scala-library, scala-reflect to 2.13.16 by @typelevel-steward in #891
- Update sbt-typelevel, ... to 0.7.7 by @typelevel-steward in #900
- Update sbt-scalajs, scalajs-compiler, ... to 1.18.2 by @typelevel-steward in #898
- flake.lock: Update by @typelevel-steward in #903
- Update scala3-library, ... to 3.3.5 by @typelevel-steward in #905
- Update opentelemetry-api, ... to 1.47.0 by @typelevel-steward in #914
- Update scalafmt-core to 3.9.1 by @typelevel-steward in #925
- Update opentelemetry-instrumentation-annotations to 2.13.2 by @typelevel-steward in #928
- Update opentelemetry-javaagent to 2.13.2 by @typelevel-steward in #929
- Update cats-effect, cats-effect-kernel, ... to 3.6.0-RC2 by @typelevel-steward in #930
- Update fs2 to
3.12.0-RC1
, removeepollcat
by @iRevive in #884 - Update opentelemetry-semconv to 1.30.0 by @typelevel-steward in #922
New Contributors
Full Changelog: v0.12.0-RC2...v0.12.0-RC3
v0.12.0-RC2
v0.12.0-RC1
That is the first candidate of the upcoming 0.12.0
release.
This version uses Cats Effect 3.6.0-RC1.
Warning
otel4s-oteljava
wasn't released due to a mistake. Please, use 0.12.0-RC2
.
New features
Cats Effect IO Runtime metrics
Documentation: https://typelevel.org/otel4s/instrumentation/metrics-cats-effect-io-runtime.html.
Configure the build.sbt
:
libraryDependencies ++= Seq(
"org.typelevel" %%% "otel4s-instrumentation-metrics" % "0.12.0-RC1"
)
Use IORuntimeMetrics.register
to register collectors:
import cats.effect._
import org.typelevel.otel4s.instrumentation.ce.IORuntimeMetrics
import org.typelevel.otel4s.metrics.MeterProvider
import org.typelevel.otel4s.trace.TracerProvider
import org.typelevel.otel4s.oteljava.OtelJava
object Main extends IOApp.Simple {
def run: IO[Unit] =
OtelJava.autoConfigured[IO]().use { otel4s =>
implicit val mp: MeterProvider[IO] = otel4s.meterProvider
IORuntimeMetrics
.register[IO](runtime.metrics, IORuntimeMetrics.Config.default)
.surround {
program(otel4s.meterProvider, otel4s.tracerProvider)
}
}
def program(
meterProvider: MeterProvider[IO],
tracerProvider: TracerProvider[IO]
): IO[Unit] = {
val _ = (meterProvider, tracerProvider)
IO.unit
}
}
OtelJava: seamless context propagation
Warning
The IOLocalContextStorageProvider
doesn't work with OpenTelemetry Java Agent.
Documentation: https://typelevel.org/otel4s/oteljava/tracing-context-propagation.html.
Configure the build.sbt
:
libraryDependencies ++= Seq(
"org.typelevel" %% "otel4s-oteljava" % "0.12.0-RC1",
"org.typelevel" %% "otel4s-oteljava-context-storage" % "0.12.0-RC1",
)
javaOptions += "-Dcats.effect.trackFiberContext=true"
Use IOLocalContextStorage.localProvider
as a LocalProvider
:
import cats.effect.IO
import io.opentelemetry.api.trace.{Span => JSpan}
import org.typelevel.otel4s.context.LocalProvider
import org.typelevel.otel4s.oteljava.IOLocalContextStorage
import org.typelevel.otel4s.oteljava.OtelJava
import org.typelevel.otel4s.oteljava.context.Context
import org.typelevel.otel4s.trace.Tracer
def program(tracer: Tracer[IO]): IO[Unit] =
tracer.span("test").use { span => // start 'test' span using otel4s
println(s"jctx: ${JSpan.current().getSpanContext}") // get a span from a ThreadLocal var
IO.println(s"otel4s: ${span.context}")
}
def run: IO[Unit] = {
implicit val provider: LocalProvider[IO, Context] =
IOLocalContextStorage.localProvider[IO]
OtelJava.autoConfigured[IO]().use { otelJava =>
otelJava.tracerProvider.tracer("com.service").get.flatMap { tracer =>
program(tracer)
}
}
}
What's Changed
Core
- core-common: remove public
localForIOLocal
instance by @iRevive in #868 - Add
IORuntimeMetrics
by @iRevive in #861 - Add
IOLocalContextStorage
by @rossabaker in #214
SDK
- sdk: refactor SpanProcessor by @iRevive in #856
- Update cats-effect to
3.6.0-RC1
, resolve compilation issues by @iRevive in #866
SDK exporter
Semantic Conventions
- Update opentelemetry-semconv to 1.29.0-alpha by @typelevel-steward in #869
OtelJava
Documentation
Dependencies
- Update sbt, scripted-plugin to 1.10.6 by @typelevel-steward in #857
- Update sbt-scalajs, scalajs-compiler, ... to 1.17.0 by @typelevel-steward in #862
- Update http4s-circe, http4s-dsl, ... to 0.23.30 by @typelevel-steward in #863
- Update opentelemetry-api, ... to 1.45.0 by @typelevel-steward in #864
- Update sbt, scripted-plugin to 1.10.7 by @typelevel-steward in #872
- Update opentelemetry-javaagent to 2.11.0 by @typelevel-steward in #874
- Update opentelemetry-instrumentation-annotations to 2.11.0 by @typelevel-steward in #873
- Update sbt-typelevel, ... to 0.7.5 by @typelevel-steward in #875
- flake.lock: Update by @typelevel-steward in #876
Uncategorized
- Update io.opentelemetry.instrumentation to 2.10.0-alpha by @iRevive in #859
- Update opentelemetry-proto to 1.4.0-alpha by @iRevive in #858
New Contributors
Full Changelog: v0.11.2...v0.12.0-RC1
v0.11.2
The release is fully binary compatible with 0.11.x
series.
What's Changed
SDK exporter
Documentation
- docs: describe
SpanOps#startUnmanaged
limitations by @iRevive in #850 - docs: add OtelJava section by @iRevive in #839
- Scaladoc: use
@note
tag by @iRevive in #852 - docs: update scala-cli directives (lib -> dep, java-opt -> javaOpt) by @iRevive in #840
- docs: add SDK testkit documentation by @iRevive in #841
- docs: add OtelJava testkit documentation by @iRevive in #842
- docs: fix dependency in oteljava testkit example by @iRevive in #843
- docs: sort metrics by name by @iRevive in #844
- docs: improve overview, describe features by @iRevive in #845
- docs: Fix curl request example for prometheus exporter by @lenguyenthanh in #851
Dependencies
- Update cats-effect, cats-effect-kernel, ... to 3.5.6 by @typelevel-steward in #847
- Update cats-effect, cats-effect-kernel, ... to 3.5.7 by @typelevel-steward in #854
- flake.lock: Update by @typelevel-steward in #855
Uncategorized
Full Changelog: v0.11.1...v0.11.2