Quickstart
This guide will help you get started with otel4s and create your first instrumented application with both metrics and tracing.Which module do I need?
Before getting started, determine which module suits your use case:- Developing an application and want to export telemetry → Use
otel4s-oteljava - Developing a library and only need trace interfaces → Use
otel4s-core-trace - Developing a library and need both tracing and metrics → Use
otel4s-core
otel4s-oteljava to build a complete application with telemetry export.
Installation
- sbt
- scala-cli
Add the following to your Explanation:
build.sbt:build.sbt
- Add the
otel4s-oteljavalibrary - Add an OpenTelemetry exporter (without it, the application will crash)
- Add the OpenTelemetry autoconfigure extension
- Enable OpenTelemetry SDK autoconfigure mode
Create your first instrumented application
Initialize OtelJava
Use
OtelJava.autoConfigured to create an otel4s instance. This method reads configuration from environment variables and system properties:Implement your instrumented program
Create meters and tracers, then use them to collect metrics and traces:
Complete example
Here’s the complete working example:Main.scala
Using the noop Tracer and Meter
If you use a library that supports otel4s (e.g., Skunk) but don’t want to use OpenTelemetry, you can provide no-op instances:- Scala 2
- Scala 3
Using imports:Using implicit vals:
Next steps
Module structure
Learn about the modular architecture and which module you need
Tracing guide
Deep dive into distributed tracing with otel4s
Metrics guide
Learn how to collect and export metrics
Examples
Explore working examples with real backends