Documentation
¶
Index ¶
- func ExtractNATS(ctx context.Context, msg HeaderHolder) context.Context
- func InitProvider(ctx context.Context, serviceName string, cfg ProviderConfig) (func(context.Context) error, http.Handler, error)
- func InjectNATS(ctx context.Context, msg *nats.Msg)
- func NewLogger(component string, level *slog.LevelVar, isJSON bool, otlpSampleRate float64) *slog.Logger
- func RegisterSystemMetrics(natsServer *server.Server, dedup dedupe.Deduplicator) error
- type HeaderHolder
- type ProviderConfig
- type TraceHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractNATS ¶
func ExtractNATS(ctx context.Context, msg HeaderHolder) context.Context
ExtractNATS extracts the propagation context from the NATS message header. Use this in the Worker/Subscriber when a message is received.
func InitProvider ¶
func InitProvider(ctx context.Context, serviceName string, cfg ProviderConfig) (func(context.Context) error, http.Handler, error)
InitProvider sets up the OpenTelemetry pipeline, registering only the signals enabled in cfg. Always installs the W3C TraceContext + Baggage propagator (cheap, harmless when traces are off — in-process span extraction still works against a no-op tracer provider).
Returns a shutdown function (always non-nil) and a Prometheus HTTP handler (non-nil iff PrometheusEnabled). The handler reads from a private prometheus.Registry — global registry pollution is avoided.
func InjectNATS ¶
InjectNATS injects the propagation context into the NATS message header. Use this in the API/Producer before publishing.
func NewLogger ¶
func NewLogger(component string, level *slog.LevelVar, isJSON bool, otlpSampleRate float64) *slog.Logger
NewLogger creates a production-ready logger with component tags and trace support. otlpSampleRate (in [0.0, 1.0]) caps OTLP export of DEBUG/INFO records; WARN/ERROR always export at 100% — dropping them silently during incidents is too dangerous to expose as a knob. Stdout receives 100% of records regardless.
func RegisterSystemMetrics ¶
func RegisterSystemMetrics(natsServer *server.Server, dedup dedupe.Deduplicator) error
RegisterSystemMetrics creates asynchronous gauges that periodically pull stats from embedded systems (NATS, Pebble) and push them to OpenTelemetry.
Types ¶
type HeaderHolder ¶
type ProviderConfig ¶
type ProviderConfig struct {
TracesEnabled bool
TracesSampleRate float64
MetricsEnabled bool
PrometheusEnabled bool
LogsEnabled bool
}
ProviderConfig wires the metrics/traces/logs pipeline. Each output is independently gated; SampleRate values must be in [0.0, 1.0] and only apply to head-based trace sampling. Log sampling is enforced inside NewLogger (per-level).
MetricsEnabled drives the OTLP-push metric exporter; PrometheusEnabled drives the Prometheus exposition reader. Either, both, or neither may be set — the underlying OTel MeterProvider is the shared substrate. When PrometheusEnabled is true InitProvider returns a non-nil promHandler.
The OTLP exporters take no endpoint/TLS/header options here: the OpenTelemetry SDK reads those from the standard OTEL_EXPORTER_OTLP_* env vars — endpoint (with `https://` selecting TLS via system root CAs), a custom CA via _CERTIFICATE, mutual TLS via _CLIENT_CERTIFICATE/_CLIENT_KEY, and auth _HEADERS. A malformed header is logged and skipped by the SDK (fail-soft), not fatal.
type TraceHandler ¶
TraceHandler intercepts every log call to inject OpenTelemetry IDs
func (*TraceHandler) WithAttrs ¶
func (h *TraceHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs and WithGroup must re-wrap so chained Logger.With / WithGroup calls keep going through TraceHandler.Handle. Without these, Go promotes the calls to the embedded slog.Handler and the returned handler is the unwrapped inner handler — silently dropping stdout trace-ID injection.