Documentation
¶
Overview ¶
Package obs traces and measures a Fletch app: OpenTelemetry spans for HTTP requests, Live mounts and events, Quiver jobs, and SQL statements, correlated through the context, and Prometheus metrics served as text. It plugs into the stdlib-only observer hooks of router, live, quiver, and data, and into fletch.WithObservability.
Index ¶
- Constants
- func NewRedactingHandler(base slog.Handler, allowlist ...string) slog.Handler
- type Option
- type Provider
- func (p *Provider) DataObserver() data.Observer
- func (p *Provider) Describe() (provider string, settings map[string]string)
- func (p *Provider) LiveObserver() live.Observer
- func (p *Provider) MetricsHandler() http.Handler
- func (p *Provider) MetricsPath() string
- func (p *Provider) Middleware() func(http.Handler) http.Handler
- func (p *Provider) QuiverObserver() quiver.Observer
- func (p *Provider) RouterObserver() router.Observer
- type Sensitive
Constants ¶
const RedactedText = "[redacted]"
RedactedText replaces sensitive values in logs, JSON, and spans.
const ScopeName = "github.com/fletchhq/fletch/obs"
ScopeName is the instrumentation scope of every span obs starts.
Variables ¶
This section is empty.
Functions ¶
func NewRedactingHandler ¶
NewRedactingHandler wraps base so that every attribute value is logged as "[redacted]" unless its key is in allowlist. A key inside a group matches by its own name or its dotted path ("user.id"). Messages are kept, so write them as constants. Redaction is the default because a new attribute is far more likely to leak PHI than a new message.
Types ¶
type Option ¶
type Option func(*config)
Option configures New.
func WithDropQueryText ¶
func WithDropQueryText() Option
WithDropQueryText leaves db.query.text off SQL spans, for databases whose statements can inline sensitive literals.
func WithErrorRedactor ¶
WithErrorRedactor makes every span record fn(err) instead of the error's own text, which can carry patient or card data (a constraint violation echoing a value, say). The error's type is not recorded either.
func WithMetricsPath ¶
WithMetricsPath makes fletch.WithObservability serve the metrics at path, such as "/metrics". Default: not served; mount MetricsHandler yourself, for example behind auth or on an internal port.
func WithTracerProvider ¶
func WithTracerProvider(tp trace.TracerProvider) Option
WithTracerProvider sets where spans go. Default: the global provider of go.opentelemetry.io/otel at the time New runs.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is the tracing and metrics provider. It is safe for concurrent use.
func (*Provider) DataObserver ¶
DataObserver traces and counts SQL statements. Use it with data.OpenObserved or data.ObserveConnector.
func (*Provider) Describe ¶
Describe reports the provider for fletch ax inspect. Nothing it reports is secret.
func (*Provider) LiveObserver ¶
LiveObserver traces Live mounts and actions, and measures sessions. A mount's span is a child of the request's span. A session outlives its request, so each action starts its own trace.
func (*Provider) MetricsHandler ¶
MetricsHandler serves the metrics in the Prometheus text format, version 0.0.4.
func (*Provider) MetricsPath ¶
MetricsPath is the path given to WithMetricsPath, or "".
func (*Provider) Middleware ¶
Middleware continues the caller's trace: it reads the W3C traceparent and tracestate headers (and, with WithXRay, X-Amzn-Trace-Id) into the request context, so the server span RouterObserver starts is a child of the caller's span. fletch.WithObservability installs it in front of the router; wrap the handler with it yourself otherwise.
func (*Provider) QuiverObserver ¶
QuiverObserver traces enqueues and job runs. A job's trace context is stored on the job, so its run is a child of its enqueue span when the backend keeps Job.Trace.
func (*Provider) RouterObserver ¶
RouterObserver traces and counts the requests a router serves. A span already in the request's context becomes the parent.
type Sensitive ¶
type Sensitive[T any] struct { // contains filtered or unexported fields }
Sensitive holds a value that must never reach a log, trace, or response by accident, such as a patient name or a card number. Logging it with slog, printing it with fmt, or encoding it as JSON gives "[redacted]"; Value returns the real value to code that needs it.
func (Sensitive[T]) MarshalJSON ¶
MarshalJSON encodes "[redacted]".
func (Sensitive[T]) MarshalText ¶
MarshalText encodes "[redacted]", for encoders that prefer text.