Deprecate v1.0.0 HTTP and log helpers in favour of the toolkit API
CI / test (push) Successful in 1m12s
CI / test (push) Successful in 1m12s
LogHandler and HTTPTransport now delegate to NewTraceHandler and NewHTTPTransport. HTTPMiddleware keeps its v1.0.0 metric names but shares responseWriter and normalizeMethod with NewHTTPMiddleware. The package example shows obsx.New. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
b53a6a6c30
commit
8837e8d316
8 files changed
+40
-149
No files matched your search
@@ -1,33 +1,10 @@
|
||||
package obsx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
import "log/slog"
|
||||
|
||||
// LogHandler wraps h so that records logged with a context carrying a span
|
||||
// (slog.InfoContext and friends) get trace_id and span_id attributes,
|
||||
// linking logs to traces.
|
||||
func LogHandler(h slog.Handler) slog.Handler { return logHandler{h} }
|
||||
|
||||
type logHandler struct{ slog.Handler }
|
||||
|
||||
func (h logHandler) Handle(ctx context.Context, r slog.Record) error {
|
||||
if sc := trace.SpanContextFromContext(ctx); sc.IsValid() {
|
||||
r.AddAttrs(
|
||||
slog.String("trace_id", sc.TraceID().String()),
|
||||
slog.String("span_id", sc.SpanID().String()),
|
||||
)
|
||||
}
|
||||
return h.Handler.Handle(ctx, r)
|
||||
}
|
||||
|
||||
func (h logHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||
return logHandler{h.Handler.WithAttrs(attrs)}
|
||||
}
|
||||
|
||||
func (h logHandler) WithGroup(name string) slog.Handler {
|
||||
return logHandler{h.Handler.WithGroup(name)}
|
||||
}
|
||||
//
|
||||
// Deprecated: use NewTraceHandler, which LogHandler now calls.
|
||||
func LogHandler(h slog.Handler) slog.Handler { return NewTraceHandler(h) }
|
||||
Reference in new issue
Block a user