observability

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package observability provides cross-cutting structured logging used by huan's release/deploy pipelines. The Logger emits JSON lines per CLAUDE.md's Full-Lifecycle Observability mandate.

Logger was previously in internal/deploy/logging.go; it was extracted into its own package once release became the second consumer. The abstraction is domain-agnostic (no deploy/release specifics); Report-shaped types stay in their domain packages because their fields differ.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTraceID

func NewTraceID() string

NewTraceID generates a random 16-byte hex-encoded id (32 chars). Exported so callers can pre-generate a trace id and use it both in early-return Report values and in the Logger.

Types

type EventType

type EventType string

EventType enumerates the structured log event types mandated by CLAUDE.md (Full-Lifecycle Observability).

const (
	EventFunctionStart EventType = "Function_Start"
	EventFunctionEnd   EventType = "Function_End"
	EventBranch        EventType = "Branch"
	EventError         EventType = "Error"
	EventPoint         EventType = "Point"
)

type Logger

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

Logger emits JSON-structured log lines to stderr (default). Each line has:

{
  "timestamp": "2026-06-13T...",
  "trace_id": "<invocation id>",
  "span_id": "<step id within this invocation>",
  "event_type": "Function_Start|Function_End|Branch|Error|Point",
  "payload": { ... arbitrary fields ... }
}

The Logger keeps no state about active spans — callers pass an explicit spanID per call. This avoids the implicit-global-state footguns common in context-based loggers and makes the log calls grep-friendly.

Logger is safe for concurrent use.

func NewLogger

func NewLogger(traceID string) *Logger

NewLogger returns a Logger that writes to stderr. traceID is propagated to every log line for correlation; if empty, a random one is generated.

func NewLoggerWithWriter

func NewLoggerWithWriter(traceID string, w io.Writer) *Logger

NewLoggerWithWriter is like NewLogger but lets tests inject a buffer. traceID is auto-generated when empty, matching NewLogger's contract.

func (*Logger) Log

func (l *Logger) Log(spanID string, event EventType, payload map[string]any)

Log emits one structured log line. payload may be nil.

func (*Logger) LogError

func (l *Logger) LogError(spanID string, err error, payload map[string]any)

LogError is a convenience wrapper for error events.

func (*Logger) LogFunctionEnd

func (l *Logger) LogFunctionEnd(spanID string, duration time.Duration, payload map[string]any)

func (*Logger) LogFunctionStart

func (l *Logger) LogFunctionStart(spanID string, payload map[string]any) string

LogFunctionStart and LogFunctionEnd record the boundary of a logical step (e.g. an HTTP API call or a sub-command phase). They return the same spanID for chaining.

start := l.LogFunctionStart("upload-file", map[string]any{"path": p})
defer l.LogFunctionEnd(start, time.Since(...), nil)

func (*Logger) TraceID

func (l *Logger) TraceID() string

TraceID returns the trace id used for all lines from this logger.

Jump to

Keyboard shortcuts

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