obs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package obs owns specd's structured operational logging.

Loggers are hard-wired to stderr so Brain tracing never mutates stdout, whose bytes are part of specd's deterministic CLI contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BrainLogPath

func BrainLogPath(root, sessionID string) (string, error)

BrainLogPath returns the structured timeline path for a Brain session.

func LogContextCompact

func LogContextCompact(ctx context.Context, logger *slog.Logger, session string, estimatedTokens, hostReportedTokens, budget int, reason, file string)

LogContextCompact emits a context.compact timeline event (spec §4.7): the token ledger checkpoint a host produced when shedding context. It rides the same brain.log surface as LogEvent, so `specd replay` shows it inline.

func LogEvent

func LogEvent(ctx context.Context, logger *slog.Logger, event, session, worker, task string, dur time.Duration, exit int)

LogEvent emits one stable Brain event.

func MetricsEndpointAddr

func MetricsEndpointAddr() string

MetricsEndpointAddr returns the active metrics listener address, if enabled.

func NewLogger

func NewLogger() *slog.Logger

NewLogger returns a slog logger that writes to stderr only. SPECD_LOG_FORMAT selects JSON or text output; JSON is the default.

func NewSessionLogger

func NewSessionLogger(root, sessionID string) (*slog.Logger, io.Closer)

NewSessionLogger mirrors logs to .specd/sessions/<sessionID>/brain.log. File setup is best-effort: failures are warned on stderr and logging continues to stderr only.

func ParseFormat

func ParseFormat(raw string) string

ParseFormat maps SPECD_LOG_FORMAT to a slog output mode.

func ParseLevel

func ParseLevel(raw string) slog.Level

ParseLevel maps SPECD_LOG to a slog level. Unknown values fail closed to warn.

func RecordDuration

func RecordDuration(name string, d time.Duration)

RecordDuration emits one structured duration metric through specd's existing stderr logger and stores it for the optional Prometheus text endpoint.

func RenderPrometheusMetrics

func RenderPrometheusMetrics() string

RenderPrometheusMetrics renders the in-memory duration metrics in Prometheus text exposition format without requiring a Prometheus client dependency.

func WithFields

func WithFields(ctx context.Context, slug, phase, role string) context.Context

WithFields annotates ctx with optional slug/phase/role log fields.

Types

type EndSpan

type EndSpan func()

EndSpan completes a tracing span.

func StartSpan

func StartSpan(_ string) EndSpan

StartSpan is a no-op in default builds. Returning nil lets callers avoid allocating a closure and lets the compiler erase the default instrumentation.

type TimelineEvent

type TimelineEvent struct {
	Time      string `json:"time,omitempty"`
	Level     string `json:"level,omitempty"`
	Message   string `json:"msg,omitempty"`
	Event     string `json:"event"`
	Slug      string `json:"slug,omitempty"`
	Phase     string `json:"phase,omitempty"`
	Role      string `json:"role,omitempty"`
	Session   string `json:"session,omitempty"`
	SessionID string `json:"session_id,omitempty"`
	Worker    string `json:"worker,omitempty"`
	Task      string `json:"task,omitempty"`
	DurMS     int64  `json:"dur_ms,omitempty"`
	Exit      int    `json:"exit,omitempty"`
	// Context-compaction fields (spec §4.7), present only on context.compact events.
	EstimatedTokens    int    `json:"estimated_tokens,omitempty"`
	HostReportedTokens int    `json:"host_reported_tokens,omitempty"`
	Budget             int    `json:"budget,omitempty"`
	Reason             string `json:"reason,omitempty"`
	CompactionFile     string `json:"compaction_file,omitempty"`
}

TimelineEvent is one parsed Brain structured event.

func ReadTimeline

func ReadTimeline(root, sessionID string) ([]TimelineEvent, error)

ReadTimeline parses NDJSON slog output and keeps records carrying an event.

Jump to

Keyboard shortcuts

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