Documentation
¶
Overview ¶
Package loxa provides canonical wide-event logging for Go services.
Index ¶
- Constants
- Variables
- func Add(ctx context.Context, key string, value interface{}) error
- func Append(ctx context.Context, attrs ...Attr) error
- func Checkpoint(ctx context.Context, name string, attrs ...Attr) error
- func ComposeRedactors(redactors ...core.Redactor) core.Redactor
- func Configure(cfg Config) error
- func Debug(msg string, attrs ...Attr)
- func DebugContext(ctx context.Context, msg, event string, attrs ...Attr)
- func DefaultRedactor() core.Redactor
- func Delete(ctx context.Context, keys ...string) error
- func DropKeys(keys ...string) core.Redactor
- func Emit(ctx context.Context) error
- func EmitEvent(ev *Event) error
- func Enrich(ctx context.Context, attrs ...Attr) error
- func EnrichGroup(ctx context.Context, key string, attrs ...Attr) error
- func Error(msg string, attrs ...Attr)
- func ErrorContext(ctx context.Context, msg string, err error, event string, attrs ...Attr)
- func EventID(ctx context.Context) string
- func Fatal(msg string, attrs ...Attr)
- func Finish(ctx context.Context, outcome string, attrs ...Attr) error
- func FinishError(ctx context.Context, err error, attrs ...Attr) error
- func Flush(ctx context.Context) error
- func Get(ctx context.Context, key string) (any, bool)
- func GetGroup(ctx context.Context, name string) (map[string]any, bool)
- func HasEvent(ctx context.Context) bool
- func HashKeys(keys ...string) core.Redactor
- func Info(msg string, attrs ...Attr)
- func InfoContext(ctx context.Context, msg, event string, attrs ...Attr)
- func InjectHTTPHeaderCarrier(ctx context.Context, header http.Header) http.Header
- func InjectHTTPHeaders(req *http.Request)
- func JSONEncoder() *core.JSONEventEncoder
- func MaskKeys(keys ...string) core.Redactor
- func Merge(ctx context.Context, group string, attrs ...Attr) error
- func MustShutdown(timeout time.Duration)
- func NewRoundTripper(base http.RoundTripper) http.RoundTripper
- func PanicRecoveryEnabled() bool
- func PrettyJSONEncoder() *core.JSONEventEncoder
- func RedactKeys(keys ...string) core.Redactor
- func RequestIDFromContext(ctx context.Context) string
- func RequestIDFromHTTP(r *http.Request) string
- func RunCLI(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func RunCron(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func RunEvent(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func RunHTTP(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func RunJob(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func RunQueue(ctx context.Context, params Params, fn EventFunc, finishAttrs ...Attr) error
- func Set(ctx context.Context, attrs ...Attr) error
- func SetDefault(l *Logger)
- func Shutdown(ctx context.Context) error
- func ShutdownTimeout(timeout time.Duration) error
- func SpanIDFromContext(ctx context.Context) string
- func StartCLIEvent(ctx context.Context, params Params) context.Context
- func StartCron(ctx context.Context, name string) context.Context
- func StartCronEvent(ctx context.Context, params Params) context.Context
- func StartEvent(ctx context.Context, params Params) context.Context
- func StartHTTPEvent(ctx context.Context, params Params) context.Context
- func StartHTTPEventFromRequest(r *http.Request, params Params) context.Context
- func StartJob(ctx context.Context, name string) context.Context
- func StartJobEvent(ctx context.Context, params Params) context.Context
- func StartQueueEvent(ctx context.Context, params Params) context.Context
- func StartQueueJob(ctx context.Context, queue, messageID string) context.Context
- func TraceFromOTel(ctx context.Context) (traceID string, spanID string)
- func TraceIDFromContext(ctx context.Context) string
- func Warn(msg string, attrs ...Attr)
- func WarnContext(ctx context.Context, msg, event string, attrs ...Attr)
- func WrapHTTPClient(client *http.Client) *http.Client
- type Attr
- type BackpressurePolicy
- type CollectorSinkConfig
- type Config
- type ConfigOption
- func WithAsync(enabled bool) ConfigOption
- func WithAsyncFlushInterval(interval time.Duration) ConfigOption
- func WithAsyncMaxBatchBytes(maxBytes int) ConfigOption
- func WithAsyncQueue(size int) ConfigOption
- func WithBackpressure(policy BackpressurePolicy) ConfigOption
- func WithBatchSize(size int) ConfigOption
- func WithCollectorEndpoint(endpoint string) ConfigOption
- func WithCollectorURL(url string) ConfigOption
- func WithCompression(enabled bool) ConfigOption
- func WithConnectionTimeout(timeout time.Duration) ConfigOption
- func WithDuplicatePolicy(policy DuplicateFieldPolicy) ConfigOption
- func WithEncoder(encoder Encoder) ConfigOption
- func WithEnricher(enricher ContextEnricher) ConfigOption
- func WithEnvironment(environment string) ConfigOption
- func WithEventSchema(schema Schema) ConfigOption
- func WithFallbackSink(sink Sink) ConfigOption
- func WithFlushInterval(interval time.Duration) ConfigOption
- func WithMaxBackoff(backoff time.Duration) ConfigOption
- func WithMaxBufferSize(size int) ConfigOption
- func WithMaxRetries(retries int) ConfigOption
- func WithRedactor(redactor Redactor) ConfigOption
- func WithSampler(sampler Sampler) ConfigOption
- func WithSchema(schema Schema) ConfigOption
- func WithService(service string) ConfigOption
- func WithSink(sink Sink) ConfigOption
- func WithStatsHandler(handler StatsHandler) ConfigOption
- func WithStrict(strict bool) ConfigOption
- func WithTenantID(tenantID string) ConfigOption
- func WithTimeout(timeout time.Duration) ConfigOption
- func WithVersion(version string) ConfigOption
- func WithWorkers(workers int) ConfigOption
- type ConfigValidationError
- type ContextEnricher
- type DuplicateEmitError
- type DuplicateFieldError
- type DuplicateFieldPolicy
- type Encoder
- type Event
- type EventAlreadyFinishedError
- type EventClosedError
- type EventFunc
- type EventState
- type EventView
- type FileConfig
- type Level
- type Logger
- type MemorySinkStore
- type MetricsCollector
- type Params
- type PrometheusStatsHandler
- type Redactor
- type RotatingFileConfig
- type Sampler
- func AllSampler(samplers ...Sampler) Sampler
- func AnySampler(samplers ...Sampler) Sampler
- func NotSampler(sampler Sampler) Sampler
- func SampleAll() Sampler
- func SampleByHeader(header, value string) Sampler
- func SampleErrors() Sampler
- func SampleFeatureFlag(name string, value any) Sampler
- func SampleNone() Sampler
- func SampleRandom(rate float64) Sampler
- func SampleRateLimited(rate float64, window time.Duration) Sampler
- func SampleRoutes(routes ...string) Sampler
- func SampleSlowRequests(d time.Duration) Sampler
- func SampleStatusCodes(codes ...int) Sampler
- func SampleTenants(ids ...string) Sampler
- func SampleUsers(ids ...string) Sampler
- type Schema
- type SchemaFunc
- type SecurityConfig
- type Sink
- func CollectorSink(cfg core.CollectorSinkConfig) (Sink, error)
- func FileSink(path string) (Sink, error)
- func HTTPBatchSink(endpoint string) (Sink, error)
- func MemorySink() (Sink, *core.MemorySinkStore)
- func NoopSink() Sink
- func RotatingFileSink(cfg core.RotatingFileConfig) (Sink, error)
- func StderrSink() Sink
- func StdoutSink() Sink
- type StatsHandler
Constants ¶
const ( LOXA_SPEC_VERSION = core.LOXA_SPEC_VERSION LOXA_INGEST_API_VERSION = core.LOXA_INGEST_API_VERSION LOXA_EVENT_VERSION = core.LOXA_EVENT_VERSION LevelDebug = core.LevelDebug LevelInfo = core.LevelInfo LevelWarn = core.LevelWarn LevelError = core.LevelError LevelFatal = core.LevelFatal // Backpressure policies Block = core.Block DropNewest = core.DropNewest DropOldest = core.DropOldest DropDebug = core.DropDebug DropSampled = core.DropSampled SyncFallback = core.SyncFallback // Duplicate field policies CanonicalWins = core.CanonicalWins AttrWins = core.AttrWins AttrsWin = core.AttrsWin UserWins = core.UserWins FirstWins = core.FirstWins LastWins = core.LastWins KeepBothUnderAttrs = core.KeepBothUnderAttrs DropDuplicateAttr = core.DropDuplicateAttr ErrorOnDuplicate = core.ErrorOnDuplicate KeepBoth = core.KeepBoth EventStateCreated = core.EventStateCreated EventStateActive = core.EventStateActive EventStateFinished = core.EventStateFinished EventStateEmitting = core.EventStateEmitting EventStateEmitted = core.EventStateEmitted EventStateFailedValidation = core.EventStateFailedValidation EventStateDeliveryFailed = core.EventStateDeliveryFailed )
Variables ¶
var ( // ErrInvalidConfig indicates config validation failure. ErrInvalidConfig = core.ErrInvalidConfig // ErrConfigFileNotFound is returned when no config file is found. ErrConfigFileNotFound = core.ErrConfigFileNotFound )
var ( String = core.String Int = core.Int Int64 = core.Int64 Uint64 = core.Uint64 Float64 = core.Float64 Bool = core.Bool Time = core.Time Duration = core.Duration Any = core.Any Null = core.Null Err = core.Err Stringer = core.Stringer Group = core.Group // Canonical fields RequestID = core.RequestID TraceID = core.TraceID SpanID = core.SpanID Service = core.Service Version = core.Version DeploymentID = core.DeploymentID Region = core.Region Method = core.Method Path = core.Path Route = core.Route StatusCode = core.StatusCode DurationMS = core.DurationMS Outcome = core.Outcome // Domain fields UserID = core.UserID TenantID = core.TenantID WorkspaceID = core.WorkspaceID OrganizationID = core.OrganizationID SessionID = core.SessionID OrderID = core.OrderID CartID = core.CartID ProductID = core.ProductID CustomerID = core.CustomerID Plan = core.Plan Currency = core.Currency Amount = core.Amount Country = core.Country Device = core.Device Platform = core.Platform AppVersion = core.AppVersion JobName = core.JobName QueueName = core.QueueName MessageID = core.MessageID Attempt = core.Attempt ErrorType = core.ErrorType ErrorCode = core.ErrorCode ErrorMessage = core.ErrorMessage ErrorStack = core.ErrorStack Retryable = core.Retryable // Sensitive MarkSensitive = core.MarkSensitive SensitiveString = core.SensitiveString HashString = core.HashString // Domain logic FeatureFlag = core.FeatureFlag FeatureFlagBool = core.FeatureFlagBool Experiment = core.Experiment )
Functions ¶
func Checkpoint ¶
Checkpoint records a named breadcrumb.
func DebugContext ¶
DebugContext emits an immediate debug log line with explicit context and event name.
func DefaultRedactor ¶
func EnrichGroup ¶
EnrichGroup appends attrs as a named group.
func ErrorContext ¶
ErrorContext emits an immediate error log line with explicit context and event name.
func FinishError ¶
FinishError records error outcome and metadata.
func InfoContext ¶
InfoContext emits an immediate info log line with explicit context and event name.
func InjectHTTPHeaderCarrier ¶
InjectHTTPHeaderCarrier injects LOXA + trace headers into a header map.
func InjectHTTPHeaders ¶
InjectHTTPHeaders injects LOXA + trace headers into an outbound request.
func JSONEncoder ¶
func JSONEncoder() *core.JSONEventEncoder
JSONEncoder returns the default compact JSON encoder.
func MustShutdown ¶
MustShutdown drains and closes sinks, panicking on error.
func NewRoundTripper ¶
func NewRoundTripper(base http.RoundTripper) http.RoundTripper
func PanicRecoveryEnabled ¶
func PanicRecoveryEnabled() bool
PanicRecoveryEnabled reports whether wrapper helpers recover panics.
func PrettyJSONEncoder ¶
func PrettyJSONEncoder() *core.JSONEventEncoder
PrettyJSONEncoder returns a pretty-print JSON encoder.
func RedactKeys ¶
func RequestIDFromContext ¶
RequestIDFromContext returns the request ID of the active event.
func RequestIDFromHTTP ¶
RequestIDFromHTTP resolves request id from header or active event context.
func SetDefault ¶
func SetDefault(l *Logger)
SetDefault replaces the global default logger instance.
func ShutdownTimeout ¶
ShutdownTimeout drains and closes sinks with timeout-bound context.
func SpanIDFromContext ¶
SpanIDFromContext returns the span ID of the active event.
func StartCLIEvent ¶
StartCLIEvent starts a CLI execution event.
func StartCronEvent ¶
StartCronEvent starts a cron execution event.
func StartEvent ¶
StartEvent begins a canonical wide event.
func StartHTTPEvent ¶
StartHTTPEvent starts an event with HTTP defaults.
func StartHTTPEventFromRequest ¶
StartHTTPEventFromRequest starts an HTTP event using request metadata and propagated headers. It fills Method/Path defaults from r when absent, starts the event, then enriches with extracted request/trace attrs.
func StartJobEvent ¶
StartJobEvent starts a background job event.
func StartQueueEvent ¶
StartQueueEvent starts a queue-processing event.
func StartQueueJob ¶
StartQueueJob is a convenience wrapper for queue jobs.
func TraceFromOTel ¶
TraceFromOTel returns trace/span ids from OTel span context.
func TraceIDFromContext ¶
TraceIDFromContext returns the trace ID of the active event.
func WarnContext ¶
WarnContext emits an immediate warn log line with explicit context and event name.
Types ¶
type Attr ¶
Attr is a typed key-value pair.
func ExtractHTTPHeaderAttrs ¶
ExtractHTTPHeaderAttrs extracts common LOXA tracing/request attrs from headers.
func ExtractHTTPHeaders ¶
ExtractHTTPHeaders extracts common LOXA tracing/request attrs from inbound headers.
type BackpressurePolicy ¶
type BackpressurePolicy = core.BackpressurePolicy
BackpressurePolicy determines what happens when the async queue is full.
type CollectorSinkConfig ¶
type CollectorSinkConfig = core.CollectorSinkConfig
type Config ¶
Config is the SDK configuration.
func ApplyConfig ¶
func ApplyConfig(cfg Config, options ...ConfigOption) Config
ApplyConfig applies options to cfg in order.
func LoadFromEnv ¶
LoadFromEnv loads configuration from environment variables.
func Production ¶
func Production() Config
type ConfigOption ¶
type ConfigOption = core.ConfigOption
ConfigOption mutates and returns Config.
func WithAsync ¶
func WithAsync(enabled bool) ConfigOption
func WithAsyncFlushInterval ¶
func WithAsyncFlushInterval(interval time.Duration) ConfigOption
func WithAsyncMaxBatchBytes ¶
func WithAsyncMaxBatchBytes(maxBytes int) ConfigOption
func WithAsyncQueue ¶
func WithAsyncQueue(size int) ConfigOption
func WithBackpressure ¶
func WithBackpressure(policy BackpressurePolicy) ConfigOption
func WithBatchSize ¶
func WithBatchSize(size int) ConfigOption
func WithCollectorEndpoint ¶
func WithCollectorEndpoint(endpoint string) ConfigOption
func WithCollectorURL ¶
func WithCollectorURL(url string) ConfigOption
func WithCompression ¶
func WithCompression(enabled bool) ConfigOption
func WithConnectionTimeout ¶
func WithConnectionTimeout(timeout time.Duration) ConfigOption
func WithDuplicatePolicy ¶
func WithDuplicatePolicy(policy DuplicateFieldPolicy) ConfigOption
func WithEncoder ¶
func WithEncoder(encoder Encoder) ConfigOption
func WithEnricher ¶
func WithEnricher(enricher ContextEnricher) ConfigOption
func WithEnvironment ¶
func WithEnvironment(environment string) ConfigOption
func WithEventSchema ¶
func WithEventSchema(schema Schema) ConfigOption
func WithFallbackSink ¶
func WithFallbackSink(sink Sink) ConfigOption
func WithFlushInterval ¶
func WithFlushInterval(interval time.Duration) ConfigOption
func WithMaxBackoff ¶
func WithMaxBackoff(backoff time.Duration) ConfigOption
func WithMaxBufferSize ¶
func WithMaxBufferSize(size int) ConfigOption
func WithMaxRetries ¶
func WithMaxRetries(retries int) ConfigOption
func WithRedactor ¶
func WithRedactor(redactor Redactor) ConfigOption
func WithSampler ¶
func WithSampler(sampler Sampler) ConfigOption
func WithSchema ¶
func WithSchema(schema Schema) ConfigOption
func WithService ¶
func WithService(service string) ConfigOption
func WithSink ¶
func WithSink(sink Sink) ConfigOption
func WithStatsHandler ¶
func WithStatsHandler(handler StatsHandler) ConfigOption
func WithStrict ¶
func WithStrict(strict bool) ConfigOption
func WithTenantID ¶
func WithTenantID(tenantID string) ConfigOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ConfigOption
func WithVersion ¶
func WithVersion(version string) ConfigOption
func WithWorkers ¶
func WithWorkers(workers int) ConfigOption
type ConfigValidationError ¶
type ConfigValidationError = core.ConfigValidationError
ConfigValidationError is returned when config validation fails.
type ContextEnricher ¶
type ContextEnricher = core.ContextEnricher
ContextEnricher derives attrs from context during Emit(ctx).
type DuplicateEmitError ¶
type DuplicateEmitError = core.DuplicateEmitError
DuplicateEmitError is returned when Emit is called after emitted.
type DuplicateFieldError ¶
type DuplicateFieldError = core.DuplicateFieldError
DuplicateFieldError is returned for ErrorOnDuplicate policy violations.
type DuplicateFieldPolicy ¶
type DuplicateFieldPolicy = core.DuplicateFieldPolicy
DuplicateFieldPolicy controls custom attr collisions with canonical fields.
type Event ¶
Event is the canonical wide event.
func FromContext ¶
FromContext retrieves the active Event from ctx.
type EventAlreadyFinishedError ¶
type EventAlreadyFinishedError = core.EventAlreadyFinishedError
EventAlreadyFinishedError is returned when finishing twice.
type EventClosedError ¶
type EventClosedError = core.EventClosedError
EventClosedError is returned when mutating or finishing a closed event.
type EventState ¶
type EventState = core.EventState
EventState is the canonical event lifecycle state.
type FileConfig ¶
type FileConfig = core.FileConfig
FileConfig is the YAML-serializable SDK configuration.
func LoadFromFile ¶
func LoadFromFile(path string) (FileConfig, error)
LoadFromFile loads configuration from a loxa.yaml file. If path is empty, it searches for loxa.yaml in the current directory and then in ~/.loxa/loxa.yaml. Requirements: 32.3
type Logger ¶
Logger is an instance of the logging pipeline.
type MemorySinkStore ¶
type MemorySinkStore = core.MemorySinkStore
type MetricsCollector ¶
type MetricsCollector = core.MetricsCollector
MetricsCollector exposes Prometheus metrics for SDK and transport observability.
func NewMetricsCollector ¶
func NewMetricsCollector(namespace string, maxBufferSize int) *MetricsCollector
type PrometheusStatsHandler ¶
type PrometheusStatsHandler = core.PrometheusStatsHandler
PrometheusStatsHandler wraps a MetricsCollector for StatsHandler integration.
func NewPrometheusStatsHandler ¶
func NewPrometheusStatsHandler(namespace string, maxBufferSize int) *PrometheusStatsHandler
type RotatingFileConfig ¶
type RotatingFileConfig = core.RotatingFileConfig
type Sampler ¶
Sampler decides whether an event should be emitted.
func AllSampler ¶
func AnySampler ¶
func NotSampler ¶
func SampleByHeader ¶
func SampleErrors ¶
func SampleErrors() Sampler
func SampleFeatureFlag ¶
func SampleNone ¶
func SampleNone() Sampler
func SampleRandom ¶
func SampleRoutes ¶
func SampleSlowRequests ¶
func SampleStatusCodes ¶
func SampleTenants ¶
func SampleUsers ¶
type Schema ¶
Schema controls final output shape for emitted events.
func DatadogSchema ¶
func DatadogSchema() Schema
func DefaultSchema ¶
func DefaultSchema() Schema
func FlatSchema ¶
func FlatSchema() Schema
func NestedSchema ¶
func NestedSchema() Schema
func OTelLogSchema ¶
func OTelLogSchema() Schema
func OTelSchema ¶
func OTelSchema() Schema
type SecurityConfig ¶
type SecurityConfig = core.SecurityConfig
SecurityConfig controls event-size and sensitive-data limits.
type Sink ¶
Sink is the interface for event destinations.
func CollectorSink ¶
func CollectorSink(cfg core.CollectorSinkConfig) (Sink, error)
func HTTPBatchSink ¶
func MemorySink ¶
func MemorySink() (Sink, *core.MemorySinkStore)
func RotatingFileSink ¶
func RotatingFileSink(cfg core.RotatingFileConfig) (Sink, error)
func StderrSink ¶
func StderrSink() Sink
func StdoutSink ¶
func StdoutSink() Sink
type StatsHandler ¶
type StatsHandler = core.StatsHandler
StatsHandler receives logger telemetry callbacks.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core hosts optional high-level composition helpers for LOXA-Go.
|
Package core hosts optional high-level composition helpers for LOXA-Go. |
|
examples
|
|
|
config-demo
command
|
|
|
state-machine
command
|
|
|
internal
|
|
|
core
Package core provides internal implementation utilities for LOXA-Go.
|
Package core provides internal implementation utilities for LOXA-Go. |
|
Package libs hosts shared library helpers for optional adapters.
|
Package libs hosts shared library helpers for optional adapters. |
|
middleware
module
|
|
|
Package packages groups optional package-level conveniences.
|
Package packages groups optional package-level conveniences. |
|
Package testkit provides testing helpers for LOXA event assertions and capture.
|
Package testkit provides testing helpers for LOXA event assertions and capture. |
|
Package utils hosts utility helpers used by examples and tooling.
|
Package utils hosts utility helpers used by examples and tooling. |