OpenTelemetry Slog [otelslog]
OpenTelemetry Slog is a handler for the new standard Golang structured logging library. The handler intercepts log messages and injects relevant OTel data into them. This data includes trace and span IDs that help correlate logs with specific requests or operations within a distributed system.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework that aims to standardize and simplify the collection, processing, and export of telemetry data from applications and systems.
OpenTelemetry supports multiple programming languages and platforms, making it suitable for a wide range of applications and environments.
OpenTelemetry enables developers to instrument their code and collect telemetry data, which can then be exported to various OpenTelemetry backends or observability platforms for analysis and visualization.
Otelslog
To install otelslog instrumentation:
go get go.opentelemetry.io/contrib/bridges/otelslog
To configure slog with Otel handler:
import "go.opentelemetry.io/contrib/bridges/otelslog"
slog.SetDefault(otelslog.NewLogger("app_or_package_name"))
Usage
Here is how you configure slog and OpenTelemetry:
package main
import (
"context"
"fmt"
"log/slog"
"os"
slogotel "github.com/remychantenay/slog-otel"
"github.com/uptrace/uptrace-go/uptrace"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
func main() {
ctx := context.Background()
uptrace.ConfigureOpentelemetry()
defer uptrace.Shutdown(ctx)
// Configure slog with Otel handler.
slog.SetDefault(otelslog.NewLogger("app_or_package_name"))
tracer := otel.Tracer("slog-example")
ctx, span := tracer.Start(ctx, "operation-name")
defer span.End()
slog.ErrorContext(ctx, "Hello world!", "locale", "en_US")
fmt.Println(uptrace.TraceURL(trace.SpanFromContext(ctx)))
}
OpenTelemetry Slog adheres to the OpenTelemetry standards, ensuring compatibility with various tracing and monitoring tools that support OpenTelemetry. This flexibility prevents vendor lock-in and simplifies integration with your existing monitoring infrastructure.
What is Uptrace?
Uptrace is a OpenTelemetry APM that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.
Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.
In just a few minutes, you can try Uptrace by visiting the cloud demo (no login required) or running it locally with Docker. The source code is available on GitHub.
What's next?
OpenTelemetry Slog is a valuable tool for improving the observability of Golang applications that use Slog for logging. By correlating logs with OpenTelemetry trace context, you can gain a deeper understanding of your application's behavior and more effectively diagnose problems and optimize performance. For comprehensive Go instrumentation, see the OpenTelemetry Go guide and explore top APM tools.