observability

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HooksFromLogger

func HooksFromLogger(logger StructuredLogger) apptheory.ObservabilityHooks

Types

type ErrorNotifier

type ErrorNotifier interface {
	Notify(ctx context.Context, entry LogEntry) error
}

type LogEntry

type LogEntry struct {
	Timestamp time.Time      `json:"timestamp"`
	Level     string         `json:"level"`
	Message   string         `json:"message"`
	Fields    map[string]any `json:"fields,omitempty"`

	RequestID string `json:"request_id,omitempty"`
	TenantID  string `json:"tenant_id,omitempty"`
	UserID    string `json:"user_id,omitempty"`
	TraceID   string `json:"trace_id,omitempty"`
	SpanID    string `json:"span_id,omitempty"`
}

LogEntry represents a structured log entry.

This type is intentionally small and stable so implementations can adapt it to their backend.

type LoggerConfig

type LoggerConfig struct {
	Format       string        `json:"format"`
	Level        string        `json:"level"`
	RetryDelay   time.Duration `json:"retry_delay"`
	BatchSize    int           `json:"batch_size"`
	BufferSize   int           `json:"buffer_size"`
	MaxRetries   int           `json:"max_retries"`
	EnableStack  bool          `json:"enable_stack"`
	EnableCaller bool          `json:"enable_caller"`
}

LoggerConfig configures logger implementations.

Fields are intentionally aligned with Lift’s `observability.LoggerConfig` where it matters for migrations.

type LoggerFactory

type LoggerFactory interface {
	CreateConsoleLogger(config LoggerConfig) (StructuredLogger, error)
	CreateTestLogger() StructuredLogger
	CreateNoOpLogger() StructuredLogger
}

type LoggerStats

type LoggerStats struct {
	LastFlush      time.Time     `json:"last_flush"`
	LastError      string        `json:"last_error,omitempty"`
	EntriesLogged  int64         `json:"entries_logged"`
	EntriesDropped int64         `json:"entries_dropped"`
	FlushCount     int64         `json:"flush_count"`
	ErrorCount     int64         `json:"error_count"`
	AverageFlush   time.Duration `json:"average_flush_time"`
}

type SanitizerFunc

type SanitizerFunc func(key string, value any) any

type StructuredLogger

type StructuredLogger interface {
	Debug(message string, fields ...map[string]any)
	Info(message string, fields ...map[string]any)
	Warn(message string, fields ...map[string]any)
	Error(message string, fields ...map[string]any)

	WithField(key string, value any) StructuredLogger
	WithFields(fields map[string]any) StructuredLogger

	WithRequestID(requestID string) StructuredLogger
	WithTenantID(tenantID string) StructuredLogger
	WithUserID(userID string) StructuredLogger
	WithTraceID(traceID string) StructuredLogger
	WithSpanID(spanID string) StructuredLogger

	Flush(ctx context.Context) error
	Close() error
	IsHealthy() bool
	GetStats() LoggerStats
}

StructuredLogger is the primary Go logging surface used by Pay Theory migrations.

It intentionally mirrors the Lift logger API shape (message + map fields) while allowing implementations to provide stronger guarantees (sanitization, health, lifecycle).

func NewNoOpLogger

func NewNoOpLogger() StructuredLogger

type TestLogger

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

TestLogger is an in-memory logger implementation for deterministic unit tests.

Derived loggers (via With* calls) share the same underlying core.

func NewTestLogger

func NewTestLogger() *TestLogger

func (*TestLogger) Close

func (l *TestLogger) Close() error

func (*TestLogger) Debug

func (l *TestLogger) Debug(message string, fields ...map[string]any)

func (*TestLogger) Entries

func (l *TestLogger) Entries() []LogEntry

func (*TestLogger) Error

func (l *TestLogger) Error(message string, fields ...map[string]any)

func (*TestLogger) Flush

func (l *TestLogger) Flush(ctx context.Context) error

func (*TestLogger) GetStats

func (l *TestLogger) GetStats() LoggerStats

func (*TestLogger) Info

func (l *TestLogger) Info(message string, fields ...map[string]any)

func (*TestLogger) IsHealthy

func (l *TestLogger) IsHealthy() bool

func (*TestLogger) Warn

func (l *TestLogger) Warn(message string, fields ...map[string]any)

func (*TestLogger) WithField

func (l *TestLogger) WithField(key string, value any) StructuredLogger

func (*TestLogger) WithFields

func (l *TestLogger) WithFields(fields map[string]any) StructuredLogger

func (*TestLogger) WithRequestID

func (l *TestLogger) WithRequestID(requestID string) StructuredLogger

func (*TestLogger) WithSpanID

func (l *TestLogger) WithSpanID(spanID string) StructuredLogger

func (*TestLogger) WithTenantID

func (l *TestLogger) WithTenantID(tenantID string) StructuredLogger

func (*TestLogger) WithTraceID

func (l *TestLogger) WithTraceID(traceID string) StructuredLogger

func (*TestLogger) WithUserID

func (l *TestLogger) WithUserID(userID string) StructuredLogger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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