Deprecate v1.0.0 HTTP and log helpers in favour of the toolkit API
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:
M.ShakhmatovandClaude Fable 5.2 committed 2026-11-15 16:43:33 +03:00
1 parent b53a6a6c30
commit 8837e8d316
8 files changed
+40 -149

No files matched your search

+1 -35
View File
@@ -19,7 +19,7 @@ import (
// A complete HTTP service: one call to New wires logging, tracing, metrics,
// health checks and the admin server; instrumentation is a single wrapper.
func ExampleNew() {
func Example() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
@@ -140,37 +140,3 @@ func ExampleTrace() {
})
_ = err
}
// A service with traces, metrics and trace-correlated logs.
func Example() {
ctx := context.Background()
shutdown, err := obsx.SetupTracer(ctx, obsx.TracerConfig{
ServiceName: "orders-api",
Endpoint: "localhost:4317",
Insecure: true,
})
if err != nil {
log.Fatal(err)
}
defer shutdown(ctx)
slog.SetDefault(slog.New(obsx.LogHandler(slog.NewJSONHandler(os.Stderr, nil))))
metrics := obsx.NewMetrics(obsx.MetricsConfig{Namespace: "orders"})
orders := metrics.Counter("created_total", "Orders created.", "kind")
mux := http.NewServeMux()
mux.Handle("GET /metrics", metrics.Handler())
mux.HandleFunc("POST /orders", func(w http.ResponseWriter, r *http.Request) {
ctx, span := obsx.StartSpan(r.Context(), "create-order")
defer span.End()
orders.WithLabelValues("web").Inc()
slog.InfoContext(ctx, "order created") // carries trace_id and span_id
})
// Outgoing calls made with this client continue the current trace.
_ = &http.Client{Transport: obsx.HTTPTransport(nil)}
_ = http.ListenAndServe(":8080", obsx.HTTPMiddleware(metrics)(mux))
}