observability

package
v0.0.0-...-0301fe8 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 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

Index

Constants

View Source
const (
	// SensitiveURLParamPattern redacts secret-bearing URL query parameter
	// values (?api_key=..., &token=...).
	SensitiveURLParamPattern = `(?i)([?&](?:api[_-]?key|access[_-]?token|auth(?:orization)?|client[_-]?secret|password|passwd|secret|token)=)[^&\s'"]+`
	// SensitiveAuthSchemePattern redacts HTTP auth-scheme credentials
	// (Bearer eyJ..., Basic dXNlcjpwYXNz).
	SensitiveAuthSchemePattern = `(?i)(\b(?:bearer|basic)\s+)[A-Za-z0-9._~+/=-]+`
	// SensitiveKeyValuePattern redacts bare key=value / key: value forms.
	// The trailing (?:\s+\[REDACTED\])? exists solely to collapse
	// SensitiveAuthSchemePattern's output ("Authorization: Bearer [REDACTED]"
	// -> "Authorization: [REDACTED]", see redact_test.go), which only works
	// because this pattern runs AFTER the auth-scheme pattern in
	// sensitiveLogPatterns. Reordering the slice silently changes results.
	SensitiveKeyValuePattern = `` /* 162-byte string literal not displayed */
	// SensitiveJSONFieldPattern redacts quoted-key JSON string fields
	// ({"password":"hunter2"}), the dominant structured-log form and this
	// project's own logging convention. It replaces the entire quoted value,
	// so after SensitiveAuthSchemePattern has run,
	// {"Authorization":"Bearer x"} collapses to
	// {"Authorization":"[REDACTED]"}. Best-effort limits: only the exact key
	// names listed match (a compound key like "refresh_token" does NOT,
	// mirroring the \b behavior of SensitiveKeyValuePattern), only string
	// values are redacted (numeric/object values pass through), and escaped
	// quotes inside the value ("pa\"ss") are handled but an escaped quote
	// inside the KEY defeats the match.
	SensitiveJSONFieldPattern = `` /* 130-byte string literal not displayed */
)

Log-body redaction is the barrier between log-borne secrets and authenticated viewers who are allowed to inspect telemetry, so treat every change in this file as security-sensitive.

Coverage boundary: redaction is applied ONLY to log body fields on the read path — Logs entries, trace-correlated logs, panel reads (structured and SQL), variable options, empty-panel diagnosis, exemplars, and the SQL-side search filter built from these same patterns (see redactLogBodySQL). Span status_message, span/log attributes, and all on-disk data are NOT redacted.

The patterns are exported string constants (not just compiled regexps) so the identical RE2 source can be embedded in DuckDB regexp_replace() calls: DuckDB uses RE2, the same engine as Go's regexp, which keeps Go-side display redaction and SQL-side search redaction in lockstep (TestRedactSQLMatchesGo asserts the parity). Case-insensitivity comes from the inline (?i) flags, never from engine options.

Variables

View Source
var (
	ErrInvalidScope = errors.New("invalid observability query scope")
	ErrInvalidLimit = errors.New("invalid observability query limit")
)

Functions

func RedactLogBodySQL

func RedactLogBodySQL(column string) string

RedactLogBodySQL shares the existing read-path expression with panel projections.

Types

type DB

type DB = queryrows.Queryer

type Dependencies

type Dependencies struct {
	Service           string           `json:"service"`
	Direction         string           `json:"direction"`
	Nodes             []DependencyNode `json:"nodes"`
	MaxDepth          int              `json:"max_depth"`
	MaxNodes          int              `json:"max_nodes"`
	Truncated         bool             `json:"truncated"`
	DepthLimitReached bool             `json:"depth_limit_reached"`
	NodeLimitReached  bool             `json:"node_limit_reached"`
}

type DependencyNode

type DependencyNode struct {
	Namespace string `json:"namespace"`
	Service   string `json:"service"`
	Hops      int    `json:"hops"`
}

type DependencyOptions

type DependencyOptions struct {
	Service   string
	Direction string
	MaxDepth  int
	MaxNodes  int
}

type Edge

type Edge struct {
	Caller    string  `json:"caller"`
	Callee    string  `json:"callee"`
	Type      string  `json:"type"`
	Calls     int64   `json:"calls"`
	AverageMS float64 `json:"average_ms"`
	ErrorRate float64 `json:"error_rate"`
}

type Health

type Health string
const (
	HealthHealthy   Health = "healthy"
	HealthDegraded  Health = "degraded"
	HealthUnhealthy Health = "unhealthy"
	// HealthUnknown is what a window with no telemetry reports. Silence is not
	// health: a namespace filter that matches nothing, an agent that stopped
	// exporting and an interval before onboarding all land here, and calling
	// any of them "healthy" states the opposite of what is known.
	HealthUnknown Health = "unknown"
)

type HealthCounts

type HealthCounts struct {
	Healthy   int `json:"healthy"`
	Degraded  int `json:"degraded"`
	Unhealthy int `json:"unhealthy"`
}

type HealthTrend

type HealthTrend struct {
	Times  []int64
	Values []float64
}

type LogEntry

type LogEntry struct {
	Time     time.Time `json:"time"`
	Severity string    `json:"severity"`
	Service  string    `json:"service"`
	Body     string    `json:"body"`
	TraceID  string    `json:"trace_id,omitempty"`
	SpanID   string    `json:"span_id,omitempty"`
}

type Overview

type Overview struct {
	Health       Health          `json:"health"`
	Counts       HealthCounts    `json:"counts"`
	TotalSpans   int64           `json:"total_spans"`
	ErrorRate    float64         `json:"error_rate"`
	Services     []ServiceHealth `json:"services"`
	ServiceCount int             `json:"service_count"`
}

type Provenance

type Provenance struct {
	Window    string    `json:"window"`
	Generated time.Time `json:"generated_at"`
	Complete  bool      `json:"complete"`
}

Provenance describes the observed window and freshness.

type Result

type Result[T any] struct {
	Summary    string     `json:"summary"`
	Data       T          `json:"data"`
	Provenance Provenance `json:"provenance"`
}

Result is the canonical query envelope shared by REST and MCP. Summary is deliberately compact model context; Data remains authoritative. UI selection is deliberately absent: MCP Apps link tools to UI resources through standard tool metadata rather than a Pitot-specific view registry.

type Scope

type Scope struct {
	Service   string    `json:"service,omitempty"`
	Namespace string    `json:"namespace"`
	Start     time.Time `json:"start"`
	End       time.Time `json:"end"`
}

Scope is the mandatory boundary for every telemetry query. Namespace is a query filter, not an authorization boundary: every MCP tool input exposes it (Server.scope copies input.Namespace into the Scope) and the HTTP API reads it from a query param, so any caller — including models — may select any namespace. Do not rely on it for access control.

type Service

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

func New

func New(db DB, repository traceReader, retentionDays int) *Service

func (*Service) Dependencies

func (s *Service) Dependencies(ctx context.Context, scope Scope, options DependencyOptions) (Result[Dependencies], error)

func (*Service) HealthErrorTrend

func (s *Service) HealthErrorTrend(ctx context.Context, scope Scope) (HealthTrend, error)

func (*Service) Overview

func (s *Service) Overview(ctx context.Context, scope Scope, limit int) (Overview, error)

func (*Service) Topology

func (s *Service) Topology(ctx context.Context, scope Scope, limit int) (Topology, error)

func (*Service) Trace

func (s *Service) Trace(ctx context.Context, scope Scope, traceID, service string, limit int) (Result[TraceDetail], error)

type ServiceHealth

type ServiceHealth struct {
	Service     string  `json:"service"`
	Health      Health  `json:"health"`
	Spans       int64   `json:"spans"`
	ErrorRate   float64 `json:"error_rate"`
	P50MS       float64 `json:"p50_ms"`
	P95MS       float64 `json:"p95_ms"`
	LogCount    int64   `json:"log_count"`
	MetricCount int64   `json:"metric_count"`
}

type Topology

type Topology struct {
	Nodes []ServiceHealth `json:"nodes"`
	Edges []Edge          `json:"edges"`
}

type TraceDetail

type TraceDetail struct {
	TraceID    string      `json:"trace_id"`
	DurationMS float64     `json:"duration_ms"`
	HasError   bool        `json:"has_error"`
	Services   []string    `json:"services"`
	Spans      []TraceSpan `json:"spans"`
	Logs       []LogEntry  `json:"logs"`
	// SpanCount and ServiceCount describe the trace. Spans and Services
	// describe the page the limit admitted, which may be narrower.
	SpanCount    int  `json:"span_count"`
	ServiceCount int  `json:"service_count"`
	Truncated    bool `json:"truncated"`
}

type TraceSpan

type TraceSpan struct {
	SpanID        string    `json:"span_id"`
	ParentSpanID  string    `json:"parent_span_id,omitempty"`
	Service       string    `json:"service"`
	Operation     string    `json:"operation"`
	Kind          string    `json:"kind"`
	Start         time.Time `json:"start"`
	DurationMS    float64   `json:"duration_ms"`
	Status        string    `json:"status"`
	StatusMessage string    `json:"status_message,omitempty"`
}

Jump to

Keyboard shortcuts

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