Skip to content

Observability & health

Fetch the module first: go get github.com/yshengliao/gortexa@v0.27.0. Every snippet below is compile-verified against v0.27.0.

A three-state registry (Healthy / Degraded / Unhealthy; Degraded still counts as serving, only Unhealthy does not) plus a bridge to the standard gRPC health protocol. Normally you use the App’s own registry via app.Health() rather than building your own.

import "github.com/yshengliao/gortexa/health"
app.Health().Register("db", func(ctx context.Context) health.State {
return health.Healthy
})
overall := app.Health().Overall(ctx) // health.Healthy / Degraded / Unhealthy

Registered checks are aggregated by /readyz; Names(), Snapshot(ctx) and State(ctx, name) query them.

The gRPC instrumentation is a StatsHandler (not interceptors). Tracing/metrics export via OTLP when an endpoint is configured, and are no-ops otherwise. Each Setup* returns a ShutdownFunc.

import "github.com/yshengliao/gortexa/observability"
log, logShutdown, err := observability.SetupLogs(ctx, cfg.Log, cfg.Observ)
traceShutdown, err := observability.SetupTracing(ctx, cfg.Observ)
metricShutdown, err := observability.SetupMetrics(ctx, cfg.Observ)
// pass observability.ServerStatsHandler() to kernel.WithStatsHandler,
// and the three ShutdownFuncs to kernel.WithShutdownHook.

To export to an OTLP backend that needs an auth header (Uptrace, for example), the OTel SDK reads the standard OTEL_EXPORTER_OTLP_HEADERS env var (e.g. uptrace-dsn=<DSN>), or relay through a collector.