observ

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Variables

This section is empty.

Functions

func HealthHandler

func HealthHandler(cfg HealthConfig, roomCount, peerCount, sessionCount func() int) http.HandlerFunc

HealthHandler returns an HTTP handler for /health.

func MetricsHandler

func MetricsHandler(cfg MetricsConfig, metrics *Metrics, roomCount, peerCount, callCount func() int64) http.HandlerFunc

MetricsHandler returns an HTTP handler for /metrics.

func RecordError

func RecordError(span trace.Span, err error)

Types

type AsyncHandler

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

AsyncHandler wraps a slog.Handler to provide non-blocking logging.

func NewAsyncHandler

func NewAsyncHandler(next slog.Handler, bufferSize int) *AsyncHandler

func (*AsyncHandler) Enabled

func (h *AsyncHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*AsyncHandler) Handle

func (h *AsyncHandler) Handle(ctx context.Context, r slog.Record) error

func (*AsyncHandler) WithAttrs

func (h *AsyncHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*AsyncHandler) WithGroup

func (h *AsyncHandler) WithGroup(name string) slog.Handler

type HealthConfig

type HealthConfig struct {
	EnableAuth bool
	JWTAuth    *auth.JWTAuth
}

HealthConfig holds configuration for the health endpoint.

type LogLevel

type LogLevel = slog.Level

LogLevel represents the severity of a log entry.

type LogOutput

type LogOutput int

LogOutput controls where logs are written.

const (
	OutputStderr LogOutput = iota
	OutputStdout
	OutputJSON
	OutputAuto
)

type Logger

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

Logger is a production-grade structured logger wrapping slog. It supports asynchronous, non-blocking logging and automatic format detection.

func NewLogger

func NewLogger(level LogLevel) *Logger

NewLogger creates a production-ready logger.

func NewLoggerWithOutput

func NewLoggerWithOutput(level LogLevel, output LogOutput) *Logger

NewLoggerWithOutput creates a Logger with a specific output format.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug logs a debug-level message.

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error logs an error-level message.

func (*Logger) GetLevel

func (l *Logger) GetLevel() LogLevel

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info logs an info-level message.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel changes the minimum log level at runtime.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

Warn logs a warning-level message.

func (*Logger) WithComponent

func (l *Logger) WithComponent(name string) *Logger

WithComponent returns a new Logger scoped to a named component.

func (*Logger) WithFields

func (l *Logger) WithFields(f map[string]interface{}) *Logger

WithFields returns a new Logger with the given fields attached.

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(p string) *Logger

WithPrefix returns a new Logger with a component-style prefix.

func (*Logger) WithRequest

func (l *Logger) WithRequest(id string) *Logger

WithRequest returns a new Logger with a request ID attached.

type MemoryExporter

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

MemoryExporter stores recent spans so they can be inspected over HTTP.

func (*MemoryExporter) ExportSpans

func (e *MemoryExporter) ExportSpans(_ context.Context, spans []sdktrace.ReadOnlySpan) error

func (*MemoryExporter) Shutdown

func (e *MemoryExporter) Shutdown(context.Context) error

func (*MemoryExporter) Spans

func (e *MemoryExporter) Spans() []SpanSnapshot

type Metrics

type Metrics struct {
	ConnectionsTotal      int64
	ConnectionsActive     int64
	MessagesTotal         int64
	MessagesErrors        int64
	RoomsActive           int64
	CallsActive           int64
	PeerConnectionsActive int64
	BytesSent             int64
	BytesReceived         int64
	// contains filtered or unexported fields
}

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) AddBytesReceived

func (m *Metrics) AddBytesReceived(n int64)

func (*Metrics) AddBytesSent

func (m *Metrics) AddBytesSent(n int64)

func (*Metrics) DecConnections

func (m *Metrics) DecConnections()

func (*Metrics) IncConnections

func (m *Metrics) IncConnections()

func (*Metrics) IncMessageErrors

func (m *Metrics) IncMessageErrors()

func (*Metrics) IncMessages

func (m *Metrics) IncMessages()

func (*Metrics) PrometheusText

func (m *Metrics) PrometheusText() string

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() map[string]int64

func (*Metrics) UpdateCalls

func (m *Metrics) UpdateCalls(count int64)

func (*Metrics) UpdatePeerConnections

func (m *Metrics) UpdatePeerConnections(count int64)

func (*Metrics) UpdateRooms

func (m *Metrics) UpdateRooms(count int64)

type MetricsConfig

type MetricsConfig struct {
	EnableAuth bool
	JWTAuth    *auth.JWTAuth
}

MetricsConfig holds configuration for the metrics endpoint.

type SpanSnapshot

type SpanSnapshot struct {
	Name         string            `json:"name"`
	TraceID      string            `json:"trace_id"`
	SpanID       string            `json:"span_id"`
	ParentSpanID string            `json:"parent_span_id,omitempty"`
	Kind         string            `json:"kind"`
	Status       string            `json:"status"`
	Start        time.Time         `json:"start"`
	End          time.Time         `json:"end"`
	Attributes   map[string]string `json:"attributes,omitempty"`
}

SpanSnapshot is a lightweight JSON-safe record of an exported span.

type Tracing

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

Tracing manages the OpenTelemetry provider and in-memory exporter.

func NewTracing

func NewTracing(cfg TracingConfig) (*Tracing, error)

func (*Tracing) HTTPMiddleware

func (t *Tracing) HTTPMiddleware(next http.Handler) http.Handler

func (*Tracing) Handler

func (t *Tracing) Handler() http.HandlerFunc

func (*Tracing) Shutdown

func (t *Tracing) Shutdown(ctx context.Context) error

func (*Tracing) StartSpan

func (t *Tracing) StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

func (*Tracing) Tracer

func (t *Tracing) Tracer(name string) trace.Tracer

type TracingConfig

type TracingConfig struct {
	ServiceName    string
	ServiceVersion string
	SampleRatio    float64
	MaxSpans       int
}

TracingConfig controls built-in OpenTelemetry instrumentation.

Jump to

Keyboard shortcuts

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