OpenTelemetry oltp exporter support for slog.
- Go 1.21+ support as we use the new stdlib slog.
- Currently , only grpc otlp is supported.
import (
"context"
"log/slog"
"github.com/bakins/slogotlp"
)
func main() {
handler, err := slogotlp.NewHandler(context.Background())
// handle err
defer handler.Shutdown(context.Background())
logger := slog.New(handler)
// use logger
}
By default, slogotlp
uses environment variables for configuration.
- checks
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
then `OTEL_EXPORTER_OTLP_ENDPOINT`` for the exporter endpoint. This should be a url like "http://localhost:4317". There is no default. - If the scheme in the endpoint url is "http" or the environment variable
OTEL_EXPORTER_OTLP_LOGS_INSECURE
orOTEL_EXPORTER_OTLP_INSECURE
is set to "true", then insecure communication is used.
Currently, no other OpenTelemetry environment variables are supported.
Options may also be set when creating the log handler.
see LICENSE