Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3acf207727
commit
d1fc35fdf0
4 files changed
+300
-143
No files matched your search
@@ -1,17 +1,57 @@
|
||||
// Package obsx provides observability setup for the platform: metrics (Prometheus)
|
||||
// and tracing (OpenTelemetry).
|
||||
// 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
|
||||
//
|
||||
// // Tracing
|
||||
// shutdown, err := obsx.SetupTracer(ctx, obsx.TracerConfig{
|
||||
// ServiceName: "my-service",
|
||||
// Endpoint: "localhost:4317",
|
||||
// })
|
||||
// defer shutdown(ctx)
|
||||
// o, err := obsx.New(ctx, obsx.Config{
|
||||
// ServiceName: "orders",
|
||||
// ServiceVersion: "1.4.0",
|
||||
// Environment: "production",
|
||||
// Tracing: obsx.TracerConfig{Endpoint: "otel-collector:4317"},
|
||||
// Admin: obsx.AdminConfig{Addr: ":9090"}, // /metrics, /healthz, /readyz, pprof
|
||||
// }.WithEnv())
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// defer o.Shutdown(context.Background())
|
||||
//
|
||||
// // Metrics
|
||||
// metrics := obsx.NewMetrics(obsx.MetricsConfig{Namespace: "myapp"})
|
||||
// reqCounter := metrics.Counter("requests_total", "Total requests", "method", "status")
|
||||
// http.Handle("/metrics", metrics.Handler())
|
||||
// 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.
|
||||
package obsx
|
||||
Reference in new issue
Block a user