Files
obsx/doc.go
T
2026-11-15 16:40:52 +03:00

63 lines
2.7 KiB
Go

// Package obsx is an observability toolkit for Go microservices: structured
// logging with trace correlation (log/slog), distributed tracing
// (OpenTelemetry, OTLP), metrics (Prometheus), health checks and an admin
// endpoint — set up with one call and applied the same way in every service.
//
// # Quick Start
//
// o, err := obsx.New(ctx, obsx.Config{
// ServiceName: "orders",
// ServiceVersion: "1.4.0",
// Environment: "production",
// Tracing: obsx.TracerConfig{Endpoint: "otel-collector:4317", Insecure: true},
// Admin: obsx.AdminConfig{Addr: ":9090"}, // /metrics, /healthz, /readyz, pprof
// }.WithEnv())
// if err != nil {
// log.Fatal(err)
// }
// defer o.Shutdown(context.Background())
//
// o.Health().AddReadinessCheck("postgres", db.PingContext)
//
// http.ListenAndServe(":8080", o.HTTPMiddleware(mux)) // HTTP server
// client := o.HTTPClient() // HTTP client
// srv := grpc.NewServer(o.GRPCServerOptions()...) // gRPC server
// conn, _ := grpc.NewClient(target, o.GRPCDialOptions()...) // gRPC client
// err = o.Track(ctx, "db.get_order", func(ctx context.Context) error { ... })
//
// # Uniform telemetry
//
// Built-in instrumentation always produces the same metric names regardless of
// MetricsConfig.Namespace, so one dashboard and one set of alerts (see the
// deploy directory of the repository) cover every service:
//
// http_server_requests_total{method,route,code}
// http_server_request_duration_seconds{method,route,code}
// http_server_requests_in_flight
// http_client_requests_total{method,host,code}
// http_client_request_duration_seconds{method,host,code}
// grpc_server_requests_total{service,method,code}
// grpc_server_request_duration_seconds{service,method,code}
// grpc_server_requests_in_flight
// grpc_client_requests_total{service,method,code}
// grpc_client_request_duration_seconds{service,method,code}
// operation_duration_seconds{operation,status}
// health_check_status{check,kind}
// service_build_info{service,version,environment,revision,go_version}
//
// Latency histograms carry trace_id exemplars for sampled requests. Log
// records written with a context (slog.InfoContext etc.) carry trace_id and
// span_id.
//
// # Standalone components
//
// Every part can be used without an Observer: NewLogger, SetupTracer,
// NewMetrics, NewHealth, NewHTTPMiddleware, NewHTTPTransport and
// NewGRPCInterceptors accept explicit dependencies through config structs.
//
// # Stability
//
// The package follows semantic versioning; the v1 API is stable. The v1.0.0
// helpers HTTPMiddleware, HTTPTransport and LogHandler remain available.
package obsx