Documentation
¶
Overview ¶
Package serverboot collects the startup boilerplate shared by the long-running substrate server binaries (ateapi, atelet, ateom-gvisor): slog wiring, OTel tracer + meter providers, a Prometheus + /readyz HTTP surface, and a couple of small helpers for startup fail-fast.
Index ¶
- func Fatal(ctx context.Context, msg string, err error)
- func InitLogger()
- func InitMetrics(ctx context.Context, serviceName string) (*sdkmetric.MeterProvider, error)
- func InitTracing(ctx context.Context, opts TracingOptions) (*sdktrace.TracerProvider, error)
- func ShutdownProvider(name string, shutdown func(context.Context) error)
- func StartMetricsServer(ctx context.Context, opts MetricsServerOptions)
- type MetricsServerOptions
- type TracingOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
Fatal logs msg + err and exits with status 1. For startup-time fail-fast where there's no recovery path.
func InitLogger ¶
func InitLogger()
InitLogger sets the global slog logger to a JSON handler wrapped in contextlogging.NewHandler. Call once at process start.
func InitMetrics ¶
InitMetrics registers a global MeterProvider with both a Prometheus reader (exposed via StartMetricsServer's /metrics handler) and an OTLP periodic reader.
func InitTracing ¶
func InitTracing(ctx context.Context, opts TracingOptions) (*sdktrace.TracerProvider, error)
InitTracing registers a global TracerProvider with the given options and the TraceContext text-map propagator.
func ShutdownProvider ¶
ShutdownProvider invokes the OTel provider's Shutdown and logs any error. Designed to be deferred from main():
defer serverboot.ShutdownProvider("TracerProvider", tp.Shutdown)
func StartMetricsServer ¶
func StartMetricsServer(ctx context.Context, opts MetricsServerOptions)
StartMetricsServer runs an HTTP server exposing /metrics (Prometheus) and optionally /readyz. Blocks until http.ListenAndServe returns; designed to be `go`-launched.
Types ¶
type MetricsServerOptions ¶
type MetricsServerOptions struct {
// Addr is the TCP listen address (e.g. ":9090").
Addr string
// EnableReadyz adds a /readyz handler that returns 200 OK. Some
// binaries (ateapi) want it for Kubernetes readiness probes; others
// (atelet) historically didn't surface one.
EnableReadyz bool
}
MetricsServerOptions configures StartMetricsServer.
type TracingOptions ¶
type TracingOptions struct {
// ServiceName is required; populates resource.semconv ServiceName.
ServiceName string
// Sampler is required. ateapi typically uses ParentBased(AlwaysSample);
// atelet/ateom-gvisor use ParentBased(NeverSample).
Sampler sdktrace.Sampler
}
TracingOptions configures InitTracing.