observability

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package observability defines the versioned, redacted operational event contract shared by the CLI, API client, transfer code, and MCP server.

Index

Constants

View Source
const (
	SchemaVersion = "osf.event.v1"
	LevelDebug    = "debug"
	LevelInfo     = "info"
	LevelWarn     = "warn"
	LevelError    = "error"
	OutcomeOK     = "ok"
	OutcomeError  = "error"
	OutcomeCancel = "canceled"
)

Variables

This section is empty.

Functions

func ClassifyError

func ClassifyError(err error) string

ClassifyError maps errors to stable operational classes.

func Emit

func Emit(ctx context.Context, emitter Emitter, event Event)

Emit records an event with IDs and redaction applied.

func EndpointClass

func EndpointClass(rawURL string) string

EndpointClass returns a low-cardinality class without retaining a URL.

func NewID

func NewID(prefix string) string

NewID returns a non-secret operation or request identifier.

func OperationID

func OperationID(ctx context.Context) string

OperationID returns the operation ID associated with a context.

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request ID associated with a context.

func WithEmitter

func WithEmitter(ctx context.Context, emitter Emitter) context.Context

WithEmitter associates an event sink with a context.

func WithOperationID

func WithOperationID(ctx context.Context, id string) context.Context

WithOperationID associates an operation ID with a context.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID associates a request ID with a context.

Types

type Emitter

type Emitter interface {
	Emit(Event)
}

Emitter receives operational events. Implementations must be safe for concurrent use because API requests and MCP calls may overlap.

func EmitterFromContext

func EmitterFromContext(ctx context.Context) Emitter

EmitterFromContext returns the event sink associated with a context.

func OpenFromEnv

func OpenFromEnv(stderr io.Writer) (Emitter, io.Closer, error)

OpenFromEnv enables events only when OSF_EVENT_LOG is set. The value may be a file path or "stderr". OSF_EVENT_LEVEL defaults to info. No stdout route is supported because structured events must never pollute command output.

type Error

type Error struct {
	Class   string `json:"class"`
	Message string `json:"message"`
}

Error is a redacted, stable error classification.

func RedactedError

func RedactedError(err error, secrets ...string) *Error

RedactedError creates a stable error object without exposing credentials.

type Event

type Event struct {
	SchemaVersion string         `json:"schemaVersion"`
	Timestamp     string         `json:"timestamp"`
	Level         string         `json:"level"`
	Name          string         `json:"name"`
	Provider      string         `json:"provider,omitempty"`
	OperationID   string         `json:"operationId"`
	RequestID     string         `json:"requestId"`
	DurationMS    int64          `json:"durationMs"`
	RetryCount    int            `json:"retryCount"`
	Outcome       string         `json:"outcome"`
	EndpointClass string         `json:"endpointClass,omitempty"`
	Error         *Error         `json:"error,omitempty"`
	Fields        map[string]any `json:"fields,omitempty"`
}

Event is the stable JSON envelope emitted for an operational action.

type FileEmitter

type FileEmitter struct {
	*JSONEmitter
	// contains filtered or unexported fields
}

FileEmitter is a JSONEmitter with an owned file destination.

func (*FileEmitter) Close

func (e *FileEmitter) Close() error

Close closes the owned event log file.

type JSONEmitter

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

JSONEmitter writes one redacted JSON event per line.

func NewJSONEmitter

func NewJSONEmitter(w io.Writer, minLevel string) *JSONEmitter

NewJSONEmitter creates a concurrent JSON event sink with the given minimum level.

func (*JSONEmitter) Close

func (e *JSONEmitter) Close() error

Close closes the sink when it owns a file-backed writer.

func (*JSONEmitter) Emit

func (e *JSONEmitter) Emit(event Event)

Emit implements Emitter.

type NopEmitter

type NopEmitter struct{}

NopEmitter discards events and is the default when observability is disabled.

func (NopEmitter) Emit

func (NopEmitter) Emit(Event)

Emit implements Emitter.

Jump to

Keyboard shortcuts

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