Documentation
¶
Overview ¶
Package trail provides lightweight structured operational event journaling.
Index ¶
- Variables
- func Close() error
- func Init(cfg Config) error
- func Log(kind string, options ...Option)
- type Batch
- type Config
- type Event
- type EventID
- type ExecutionID
- type ExecutionSource
- type Field
- type FieldKind
- type FlowID
- type FullPolicy
- type Level
- type Metadata
- type Option
- func Bool(key string, value bool) Option
- func Duration(key string, value time.Duration) Option
- func Entity(entityType, entityID string) Option
- func Error(err error) Option
- func Execution(id ExecutionID) Option
- func ExecutionAttempt(attempt uint32) Option
- func Float64(key string, value float64) Option
- func Flow(id FlowID) Option
- func Int(key string, value int) Option
- func Int64(key string, value int64) Option
- func Parent(id EventID) Option
- func ParentExecution(id ExecutionID) Option
- func RetryOfExecution(id ExecutionID) Option
- func String(key, value string) Option
- func WithExecutionSource(source ExecutionSource) Option
- func WithLevel(level Level) Option
- func WithScope(scopeType, scopeID string) Option
- type Scope
- type Sink
- type Statistics
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyInitialized = errors.New("trail: already initialized") ErrInvalidConfig = errors.New("trail: invalid config") )
var (
ErrInvalidID = errors.New("trail: invalid ID")
)
Functions ¶
func Close ¶
func Close() error
Close stops the active writer, drains accepted events, and closes its Sink. Calling Close without an active writer is safe and returns nil.
Types ¶
type Batch ¶
Batch is a synchronous delivery unit. A Sink must copy it before retaining any Events or Fields after WriteBatch returns.
type Event ¶
type Event struct {
ID EventID
Timestamp int64
Kind string
Level Level
FlowID FlowID
ExecutionID ExecutionID
ParentExecutionID ExecutionID
RetryOfExecutionID ExecutionID
ExecutionAttempt uint32
ExecutionSource ExecutionSource
ScopeType string
ScopeID string
EntityType string
EntityID string
ParentID EventID
Fields []Field
}
Event is the compact record delivered to a Sink. Timestamp is Unix nanoseconds. Sinks must treat Events and their Fields as immutable.
type EventID ¶
type EventID [16]byte
EventID uniquely identifies an event.
func ParseEventID ¶
func (EventID) MarshalText ¶
func (*EventID) UnmarshalText ¶
type ExecutionID ¶
type ExecutionID [16]byte
ExecutionID correlates events produced by one job, run, or manual operation.
func NewExecution ¶
func NewExecution() ExecutionID
NewExecution returns a new stateless execution identifier.
func ParseExecutionID ¶
func ParseExecutionID(s string) (ExecutionID, error)
func (ExecutionID) IsZero ¶
func (id ExecutionID) IsZero() bool
func (ExecutionID) MarshalText ¶
func (id ExecutionID) MarshalText() ([]byte, error)
func (ExecutionID) String ¶
func (id ExecutionID) String() string
func (*ExecutionID) UnmarshalText ¶
func (id *ExecutionID) UnmarshalText(text []byte) error
type ExecutionSource ¶
type ExecutionSource string
ExecutionSource describes what initiated an execution. The constants are conventions, not a closed set; applications may use their own stable values.
const ( SourceCron ExecutionSource = "cron" SourceManual ExecutionSource = "manual" SourceQueue ExecutionSource = "queue" SourceAPI ExecutionSource = "api" SourceRetry ExecutionSource = "retry" SourceWebhook ExecutionSource = "webhook" SourceMigration ExecutionSource = "migration" )
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is a compact typed key/value pair. Its value is exposed through typed accessors so the hot path does not require an interface value.
type FlowID ¶
type FlowID [16]byte
FlowID correlates events belonging to one business flow.
func ParseFlowID ¶
func (FlowID) MarshalText ¶
func (*FlowID) UnmarshalText ¶
type FullPolicy ¶
type FullPolicy uint8
FullPolicy controls behavior when the bounded event queue is full.
const ( Drop FullPolicy = iota Block )
type Metadata ¶
Metadata is configured once and attached to batches rather than copied into every Event.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option adds correlation or a typed field to an event.
func Execution ¶
func Execution(id ExecutionID) Option
func ExecutionAttempt ¶
ExecutionAttempt uses one-based attempt numbers. Zero means unspecified.
func ParentExecution ¶
func ParentExecution(id ExecutionID) Option
func RetryOfExecution ¶
func RetryOfExecution(id ExecutionID) Option
func WithExecutionSource ¶
func WithExecutionSource(source ExecutionSource) Option
type Scope ¶ added in v0.2.0
Scope identifies the tenant or security boundary that owns an event. Scope is deliberately authorization-neutral: applications decide which authenticated principals may query a given scope.
type Sink ¶
Sink consumes batches synchronously. Ownership transfers to Trail after a successful Init; Trail calls Close exactly once after draining the writer.
type Statistics ¶
func Stats ¶
func Stats() Statistics
Stats returns a lock-free snapshot. Monotonic counters cover the process lifetime; Buffered is the current active-writer gauge.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package archive writes immutable, verifiable Trail retention bundles.
|
Package archive writes immutable, verifiable Trail retention bundles. |
|
cmd
|
|
|
trail-explorer-api
command
|
|
|
trail-generator
command
|
|
|
trail-ingestor
command
|
|
|
trail-retention
command
|
|
|
Package convention defines optional, storage-portable Trail field conventions.
|
Package convention defines optional, storage-portable Trail field conventions. |
|
examples
|
|
|
basic
command
|
|
|
flow
command
|
|
|
Package explorerapi exposes Trail's storage-neutral Explorer HTTP API.
|
Package explorerapi exposes Trail's storage-neutral Explorer HTTP API. |
|
Package generator creates deterministic, coherent Trail business stories.
|
Package generator creates deterministic, coherent Trail business stories. |
|
Package ingestor moves bounded Trail envelopes from JetStream into a storage adapter and acknowledges them only after a durable write.
|
Package ingestor moves bounded Trail envelopes from JetStream into a storage adapter and acknowledges them only after a durable write. |
|
Package payload defines storage for large data referenced by Trail events.
|
Package payload defines storage for large data referenced by Trail events. |
|
filesystem
Package filesystem provides a content-addressed development payload store.
|
Package filesystem provides a content-addressed development payload store. |
|
s3
Package s3 provides a content-addressed payload store for S3-compatible services including AWS S3, MinIO, and Cloudflare R2.
|
Package s3 provides a content-addressed payload store for S3-compatible services including AWS S3, MinIO, and Cloudflare R2. |
|
Package retention provides an optional, bounded lifecycle engine for stored Trail events and payloads.
|
Package retention provides an optional, bounded lifecycle engine for stored Trail events and payloads. |
|
sink
|
|
|
memory
Package memory provides a concurrency-safe Sink for tests and local use.
|
Package memory provides a concurrency-safe Sink for tests and local use. |
|
nats
Package nats publishes versioned Trail batches to NATS or JetStream.
|
Package nats publishes versioned Trail batches to NATS or JetStream. |
|
stdout
Package stdout provides a newline-delimited JSON Sink.
|
Package stdout provides a newline-delimited JSON Sink. |
|
Package storage defines Trail's database-neutral ingestion and Explorer contracts.
|
Package storage defines Trail's database-neutral ingestion and Explorer contracts. |
|
clickhouse
Package clickhouse implements Trail storage using ClickHouse.
|
Package clickhouse implements Trail storage using ClickHouse. |
|
postgres
Package postgres implements moderate-volume Trail storage using PostgreSQL.
|
Package postgres implements moderate-volume Trail storage using PostgreSQL. |
|
Package trailhttp journals completed outgoing HTTP requests without changing Trail's context-free core correlation model.
|
Package trailhttp journals completed outgoing HTTP requests without changing Trail's context-free core correlation model. |
|
Package wire defines Trail's versioned transport envelope.
|
Package wire defines Trail's versioned transport envelope. |