obs

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2026 License: Apache-2.0, MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const RedactedText = "[redacted]"

RedactedText replaces sensitive values in logs, JSON, and spans.

View Source
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

func NewRedactingHandler(base slog.Handler, allowlist ...string) slog.Handler

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

func WithErrorRedactor(fn func(error) string) Option

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

func WithMetricsPath(path string) Option

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.

func WithXRay

func WithXRay() Option

WithXRay makes Middleware also read the AWS X-Amzn-Trace-Id header when a request has no W3C traceparent, so traces continue from an ALB or API Gateway that only speaks X-Ray.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is the tracing and metrics provider. It is safe for concurrent use.

func New

func New(opts ...Option) *Provider

New returns a Provider. It does no I/O.

func (*Provider) DataObserver

func (p *Provider) DataObserver() data.Observer

DataObserver traces and counts SQL statements. Use it with data.OpenObserved or data.ObserveConnector.

func (*Provider) Describe

func (p *Provider) Describe() (provider string, settings map[string]string)

Describe reports the provider for fletch ax inspect. Nothing it reports is secret.

func (*Provider) LiveObserver

func (p *Provider) LiveObserver() live.Observer

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

func (p *Provider) MetricsHandler() http.Handler

MetricsHandler serves the metrics in the Prometheus text format, version 0.0.4.

func (*Provider) MetricsPath

func (p *Provider) MetricsPath() string

MetricsPath is the path given to WithMetricsPath, or "".

func (*Provider) Middleware

func (p *Provider) Middleware() func(http.Handler) http.Handler

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

func (p *Provider) QuiverObserver() quiver.Observer

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

func (p *Provider) RouterObserver() router.Observer

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 NewSensitive

func NewSensitive[T any](v T) Sensitive[T]

NewSensitive wraps v.

func (Sensitive[T]) GoString

func (Sensitive[T]) GoString() string

GoString implements fmt.GoStringer, for %#v.

func (Sensitive[T]) LogValue

func (Sensitive[T]) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Sensitive[T]) MarshalJSON

func (Sensitive[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes "[redacted]".

func (Sensitive[T]) MarshalText

func (Sensitive[T]) MarshalText() ([]byte, error)

MarshalText encodes "[redacted]", for encoders that prefer text.

func (Sensitive[T]) String

func (Sensitive[T]) String() string

String implements fmt.Stringer.

func (Sensitive[T]) Value

func (s Sensitive[T]) Value() T

Value returns the wrapped value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL