Documentation
¶
Overview ¶
Package telemetry sets up logging and metrics.
Index ¶
- func AddAttrs(ctx context.Context, attrs ...slog.Attr)
- func AddressTag(key []byte, addr string) string
- func LogKey(dataDir string) ([]byte, error)
- func LogKeyFile(dataDir string) string
- func LogPanic(ctx context.Context, msg string, v any, args ...any)
- func NewLogger(w io.Writer, level string, addressKey []byte, errs ...io.Writer) *slog.Logger
- func ReadLogKey(dataDir string) ([]byte, error)
- func WithAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- type Export
- type ExportConfig
- type Metrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAttrs ¶ added in v0.3.0
AddAttrs adds attrs to the attributes ctx carries (WithAttrs) in place, so that what is logged with the context WithAttrs returned has them as well: how a request learns its tenant once the session is known, for what its outer layers log about it. It does nothing when ctx carries none.
func AddressTag ¶ added in v0.3.0
AddressTag is what stands for addr in a log that redacts addresses: the first 8 hex digits of its HMAC-SHA256 under key, lowercased first, so the same address gets the same tag whatever its case, and no tag can be turned back into its address without key.
func LogKey ¶ added in v0.3.0
LogKey returns the key of AddressTag kept in dataDir, generating it the first time. It is kept apart from the master key so that tags stay the same when that key is replaced or retired (the hosted build keeps keys in a key service); it opens nothing, so losing it only changes every address's tag.
func LogKeyFile ¶ added in v0.3.0
LogKeyFile is where the key of AddressTag is kept in dataDir.
func LogPanic ¶ added in v0.3.0
LogPanic logs v, what recover returned, at error level under msg, with args, the panic as "panic" and the stack of the goroutine that panicked as "stack". Call it from the deferred function that recovered.
func NewLogger ¶
NewLogger returns a JSON logger that writes every record at level and above to w, and drops credentials and email bodies. With addressKey, every email address in a line, in its message as in its attributes, is written as its AddressTag under that key instead; nil keeps addresses. Each of errs gets, as well, every record at error level and above, as the one JSON line w gets for it (whatever level is): the same redaction, so it never holds more than the log does. A writer in errs must not block: the code that logged waits for it.
A record logged with a context that carries attributes (WithAttrs, AddAttrs) has them too, except those whose key the record has already.
func ReadLogKey ¶ added in v0.3.0
ReadLogKey reads the key of AddressTag from dataDir; fs.ErrNotExist when there is none.
Types ¶
type Export ¶ added in v0.3.0
type Export struct {
// contains filtered or unexported fields
}
Export sends the daemon's metrics and log to an OpenTelemetry receiver (MAI-239). The metrics are the Prometheus registry's (Metrics), read and sent by the SDK's periodic reader; the log lines are those the log writes, redaction included, handed to Write. Nothing about it ever waits on the receiver: Write only queues, and a receiver that is slow or down costs dropped lines, counted in mailrules_otel_log_records_dropped_total.
func NewExport ¶ added in v0.3.0
NewExport starts the metrics' periodic export and returns the Export whose Run sends the log lines Write queues. It connects to nothing before the first export.
type ExportConfig ¶ added in v0.3.0
type ExportConfig struct {
// Endpoint is the receiver's base URL: metrics go to /v1/metrics under it, log lines
// to /v1/logs (OTLP/HTTP, protobuf).
Endpoint string
// Headers go with every export; they hold the receiver's key, so they are never logged.
Headers map[string]string
ServiceName string
Version string
// Environment is deployment.environment.name; empty sends none.
Environment string
}
ExportConfig says where the OpenTelemetry export sends, and as what.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is the daemon's Prometheus registry. This file is the only place that imports the Prometheus client, with export.go, which hands the registry to OpenTelemetry: the HTTP layer reports through ObserveHTTP and serves Handler. A nil *Metrics records nothing.
func NewMetrics ¶
NewMetrics returns a registry with the Go runtime and process collectors, the build version and the HTTP request metrics.
func (*Metrics) DroppedError ¶ added in v0.3.0
DroppedError counts a logged error module was not handed: too many were waiting for it.