Introduces code.nochebuena.dev/einherjar/telemetry — the observability bootstrap starter for the Einherjar framework. Absorbs the telemetry package from micro-lib, migrating from OpenCensus to OpenTelemetry SDK v1.42. Bootstrap functions (not lifecycle.Component — telemetry must be initialized before the launcher starts, and its shutdown must run after all components stop): - New(ctx, cfg) (func(context.Context) error, error) — production mode; exports traces, metrics, and logs via OTLP over gRPC to the configured endpoint; returns a shutdown function to be deferred in main() - NewConsole(ctx, logger, cfg) (func(context.Context) error, error) — development mode; writes structured telemetry to the provided logging.Logger; no network dependency; suitable for local development and CI Config (EINHERJAR_OTEL_* env vars): ServiceName(required), ServiceVersion(unknown), Environment(development), OTLPEndpoint(required for New), OTLPInsecure(false) ConsoleConfig (EINHERJAR_OTEL_* env vars): ServiceName(required), ServiceVersion(unknown), Environment(development) - identifiable.go: package-level Module variable (observability.Identifiable) for version identification — telemetry bootstraps before the launcher; not registered as a lifecycle component
26 lines
1.1 KiB
Go
26 lines
1.1 KiB
Go
package telemetry
|
|
|
|
// Config holds OTel bootstrap configuration.
|
|
type Config struct {
|
|
// ServiceName identifies the service in traces, metrics, and logs.
|
|
ServiceName string `env:"EINHERJAR_OTEL_SERVICE_NAME,required"`
|
|
// ServiceVersion is the deployed version (e.g. "1.4.2").
|
|
ServiceVersion string `env:"EINHERJAR_OTEL_SERVICE_VERSION" envDefault:"unknown"`
|
|
// Environment is the deployment environment (e.g. "production", "staging").
|
|
Environment string `env:"EINHERJAR_OTEL_ENVIRONMENT" envDefault:"development"`
|
|
// OTLPEndpoint is the OTLP gRPC collector address (e.g. "alloy:4317").
|
|
OTLPEndpoint string `env:"EINHERJAR_OTEL_EXPORTER_ENDPOINT,required"`
|
|
// OTLPInsecure disables TLS for the OTLP connection. Set true in development.
|
|
OTLPInsecure bool `env:"EINHERJAR_OTEL_EXPORTER_INSECURE" envDefault:"false"`
|
|
}
|
|
|
|
// DefaultConfig returns a Config with optional fields set to production-safe defaults.
|
|
// Callers must supply ServiceName and OTLPEndpoint.
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
ServiceVersion: "unknown",
|
|
Environment: "development",
|
|
OTLPInsecure: false,
|
|
}
|
|
}
|