Documentation
¶
Index ¶
- func ExtractHeaders(ctx context.Context, h map[string][]string) context.Context
- func InitProvider(ctx context.Context, serviceName string, cfg ProviderConfig) (func(context.Context) error, http.Handler, error)
- func InjectHeaders(ctx context.Context, h map[string][]string)
- func NewLogger(component string, level *slog.LevelVar, isJSON bool, otlpSampleRate float64) *slog.Logger
- func RegisterSystemMetrics(mqStats func() (MQStats, error), pebbleStats func() map[string]int64) error
- type MQStats
- type ProviderConfig
- type TraceHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractHeaders ¶ added in v0.2.0
ExtractHeaders returns ctx carrying the propagation context found in the message headers h. A nil h returns ctx unchanged. The subscriber calls this 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 InjectHeaders ¶ added in v0.2.0
InjectHeaders writes the propagation context (trace + baggage) from ctx into the message headers h, which must be non-nil. The publisher calls this before handing a message to the broker so the consumer can pick the trace back up.
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(mqStats func() (MQStats, error), pebbleStats func() map[string]int64) error
RegisterSystemMetrics creates asynchronous gauges that periodically pull stats from embedded systems (the MQ, Pebble) and push them to OpenTelemetry. Both are read on every scrape; nil skips the MQ gauges, as a nil pebbleStats — or a nil map from it, no store being open — skips the Pebble ones. The Pebble figures are the one instance's that every tenant's seen ids share (dedupe.Embedded.Stats in production).
Types ¶
type MQStats ¶ added in v0.2.0
type MQStats struct {
Connections int64 // active client connections
InMsgs int64 // messages received, cumulative
}
MQStats is the point-in-time snapshot of the embedded message queue the system gauges observe. Reported by the mq package (mq.Broker.Stats); defined here because mq imports observability, not the other way round.
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 never fatal: traces and metrics skip that entry, while the logs exporter drops the whole variable.
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.