Logger support in otelhttp #5362
Labels
area: instrumentation
Related to an instrumentation package
blocked: specification
Waiting on clarification of the OpenTelemetry specification before progress can be made
enhancement
New feature or request
instrumentation: otelhttp
Problem Statement
The
otelhttp
middleware is an ideal place to log HTTP transactions, because important data are available, such as:Now that the minimal Go version is 1.21, in which the package
log/slog
is part of the standard library,a standard API is available to generate structured log records.
OpenTelemetry loggers can be used with the
log/slog
API viago.opentelemetry.io/contrib/bridges/otelslog
.Proposed Solution
The middleware can optionally be configured with a *slog.Logger:
If a Logger has been configured, a log record will be emitted with the same attributes as the Span:
Alternatives
Middlewares already exist to generate access logs from HTTP servers based on
net/http
and similar routers,such as https://pkg.go.dev/github.com/gorilla/handlers?utm_source=godoc#LoggingHandler . The drawbacks are that:
httpsnoop
in your middleware stack (and perhaps dangerous?)slog.Logger
.Prior Art
N/A
Additional Context
N/A
The text was updated successfully, but these errors were encountered: