log/slog handler for OTel
Configure open-telemetry provider first. See example here
Then configure slog logger with otelslog handler:
package main
import (
"context"
"github.com/agoda-com/opentelemetry-go/otelslog"
"log/slog"
)
func main() {
// configure logger provider
loggerProvider := ...
otelLogger := slog.New(otelslog.NewOtelHandler(loggerProvider, &otelslog.HandlerOptions{}))
//configure default logger
slog.SetDefault(otelLogger)
doSomething(ctx)
}
// call function with opentelemetry context provided
func doSomething(ctx context.Context) {
slog.InfoContext(ctx, "hello", slog.String("myKey", "myValue"))
}