Documentation
¶
Overview ¶
Package traceloom records structured event timelines grouped by trace ID.
It is a small, dependency-free local tracing library rather than a general logger or a distributed tracing implementation.
Index ¶
- Constants
- func CanonicalizeKey(key string) string
- func GenerateTraceID() (string, error)
- func SanitizeTraceID(traceID string) (string, bool)
- type Clock
- type Configuration
- func (c Configuration) DirectoryMode() fs.FileMode
- func (c Configuration) FailOnError() bool
- func (c Configuration) FileMode() fs.FileMode
- func (c Configuration) LogDirectory() string
- func (c Configuration) MaxArrayItems() int
- func (c Configuration) MaxDepth() int
- func (c Configuration) MaxFileBytes() int64
- func (c Configuration) MaxKeyBytes() int
- func (c Configuration) MaxPayloadNodes() int
- func (c Configuration) MaxRecordBytes() int
- func (c Configuration) MaxStringBytes() int
- func (c Configuration) RetentionDays() int
- func (c Configuration) SensitiveKeys() []string
- func (c Configuration) StrictSensitiveKeys() bool
- func (c Configuration) TrustIncomingTraceID() bool
- type ConfigurationError
- type Data
- type JSONLFileWriter
- type Option
- func WithDirectoryMode(value fs.FileMode) Option
- func WithFailOnError(value bool) Option
- func WithFileMode(value fs.FileMode) Option
- func WithMaxArrayItems(value int) Option
- func WithMaxDepth(value int) Option
- func WithMaxFileBytes(value int64) Option
- func WithMaxKeyBytes(value int) Option
- func WithMaxPayloadNodes(value int) Option
- func WithMaxRecordBytes(value int) Option
- func WithMaxStringBytes(value int) Option
- func WithOnError(handler func(error)) Option
- func WithRetentionDays(value int) Option
- func WithSensitiveKeys(keys ...string) Option
- func WithStrictSensitiveKeys(value bool) Option
- func WithTrustIncomingTraceID(value bool) Option
- type Sanitizer
- type Trace
- func (trace *Trace) Event(name string, data Data) error
- func (trace *Trace) EventContext(ctx context.Context, name string, data Data) error
- func (trace *Trace) Flush() error
- func (trace *Trace) FlushContext(ctx context.Context) error
- func (trace *Trace) ID() string
- func (trace *Trace) ParentID() string
- type TraceEvent
- type Tracer
- type TracingError
- type Writer
Constants ¶
const ( // DefaultMaxFileBytes is the soft size limit for one JSONL shard. DefaultMaxFileBytes int64 = 50 * 1024 * 1024 // DefaultMaxStringBytes is the UTF-8 byte limit for one payload string. DefaultMaxStringBytes = 64 * 1024 // DefaultMaxKeyBytes is the UTF-8 byte limit for one payload key. DefaultMaxKeyBytes = 256 // DefaultMaxRecordBytes is the byte limit for one JSONL record. DefaultMaxRecordBytes = 256 * 1024 // DefaultMaxArrayItems is the item limit applied to each array on its own. DefaultMaxArrayItems = 1000 // DefaultMaxPayloadNodes is the node budget shared by an event payload as a whole. DefaultMaxPayloadNodes = 10000 // DefaultMaxDepth limits recursive payload traversal. DefaultMaxDepth = 16 // DefaultDirectoryMode is used for newly created log directories on POSIX. DefaultDirectoryMode fs.FileMode = 0o750 // DefaultFileMode is used for newly created log shards on POSIX. DefaultFileMode fs.FileMode = 0o640 // Redacted replaces values stored under sensitive keys. Redacted = "[REDACTED]" )
const ( MaxDepthExceeded = "[MAX_DEPTH_EXCEEDED]" CircularReference = "[CIRCULAR_REFERENCE]" )
Variables ¶
This section is empty.
Functions ¶
func CanonicalizeKey ¶
CanonicalizeKey folds case and punctuation for secret-key matching.
func GenerateTraceID ¶
GenerateTraceID returns a cryptographically random 32-character lowercase hex ID.
func SanitizeTraceID ¶
SanitizeTraceID returns the accepted ID and true, or an empty string and false.
Types ¶
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is validated and immutable after construction.
func NewConfiguration ¶
func NewConfiguration(logDirectory string, options ...Option) (Configuration, error)
NewConfiguration validates options and returns an immutable configuration.
func (Configuration) DirectoryMode ¶
func (c Configuration) DirectoryMode() fs.FileMode
func (Configuration) FailOnError ¶
func (c Configuration) FailOnError() bool
func (Configuration) FileMode ¶
func (c Configuration) FileMode() fs.FileMode
func (Configuration) LogDirectory ¶
func (c Configuration) LogDirectory() string
func (Configuration) MaxArrayItems ¶
func (c Configuration) MaxArrayItems() int
func (Configuration) MaxDepth ¶
func (c Configuration) MaxDepth() int
func (Configuration) MaxFileBytes ¶
func (c Configuration) MaxFileBytes() int64
func (Configuration) MaxKeyBytes ¶
func (c Configuration) MaxKeyBytes() int
func (Configuration) MaxPayloadNodes ¶
func (c Configuration) MaxPayloadNodes() int
func (Configuration) MaxRecordBytes ¶
func (c Configuration) MaxRecordBytes() int
func (Configuration) MaxStringBytes ¶
func (c Configuration) MaxStringBytes() int
func (Configuration) RetentionDays ¶
func (c Configuration) RetentionDays() int
func (Configuration) SensitiveKeys ¶
func (c Configuration) SensitiveKeys() []string
func (Configuration) StrictSensitiveKeys ¶
func (c Configuration) StrictSensitiveKeys() bool
func (Configuration) TrustIncomingTraceID ¶
func (c Configuration) TrustIncomingTraceID() bool
type ConfigurationError ¶
type ConfigurationError struct {
Message string
}
ConfigurationError reports an invalid immutable configuration.
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
type JSONLFileWriter ¶
type JSONLFileWriter struct {
// contains filtered or unexported fields
}
JSONLFileWriter appends events to UTC date shards with size rotation.
func NewJSONLFileWriter ¶
func NewJSONLFileWriter(configuration Configuration) *JSONLFileWriter
func (*JSONLFileWriter) Close ¶
func (writer *JSONLFileWriter) Close() error
Close releases the active shard. It is terminal and idempotent: a later write is rejected instead of reopening the file.
func (*JSONLFileWriter) Write ¶
func (writer *JSONLFileWriter) Write(ctx context.Context, event TraceEvent) (err error)
type Option ¶
type Option func(*configValues)
Option customizes an immutable Configuration.
func WithDirectoryMode ¶
WithDirectoryMode sets permissions for newly created log directories.
func WithFailOnError ¶
WithFailOnError enables strict runtime tracing errors when true.
func WithFileMode ¶
WithFileMode sets permissions for newly created JSONL shards.
func WithMaxArrayItems ¶
WithMaxArrayItems caps each array in a payload on its own, so one long array does not starve the fields beside it.
func WithMaxDepth ¶
WithMaxDepth sets the recursive payload depth limit.
func WithMaxFileBytes ¶
WithMaxFileBytes sets the soft size limit for one shard.
func WithMaxKeyBytes ¶
WithMaxKeyBytes sets the UTF-8 byte limit for one payload key. A longer key is truncated and given a digest suffix, so two long keys cannot collide into one.
func WithMaxPayloadNodes ¶
WithMaxPayloadNodes bounds a payload as a whole, which stops a wide or deeply nested value from costing an unbounded amount of work.
func WithMaxRecordBytes ¶
WithMaxRecordBytes sets the byte limit for one encoded JSONL record.
func WithMaxStringBytes ¶
WithMaxStringBytes sets the UTF-8 byte limit for one payload string.
func WithOnError ¶
WithOnError observes fail-safe runtime errors. Handler panics are recovered.
func WithRetentionDays ¶
WithRetentionDays removes older date shards during the writer's first rotation.
func WithSensitiveKeys ¶
WithSensitiveKeys merges custom secret keys with the built-in defaults.
func WithStrictSensitiveKeys ¶
WithStrictSensitiveKeys disables secret-fragment matching when true.
func WithTrustIncomingTraceID ¶
WithTrustIncomingTraceID controls whether accepted inbound IDs are reused.
type Sanitizer ¶
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer normalizes one event payload without retaining per-call mutable state. It is safe for concurrent use.
func NewSanitizer ¶
func NewSanitizer(configuration Configuration) *Sanitizer
type Trace ¶
type Trace struct {
// contains filtered or unexported fields
}
Trace groups a thread-safe sequence of events under one trace ID.
func (*Trace) EventContext ¶
type TraceEvent ¶
type TraceEvent struct {
Timestamp time.Time
TraceID string
ParentTraceID string
Name string
Sequence uint64
Elapsed time.Duration
Data Data
}
TraceEvent is the public storage contract passed to Writer implementations.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer owns shared configuration, writer, sanitizer, and dropped-event metrics.
func NewFromConfiguration ¶
func NewFromConfiguration(configuration Configuration) (*Tracer, error)
NewFromConfiguration creates a tracer with the built-in JSONL writer.
func NewWithDependencies ¶
func NewWithDependencies(configuration Configuration, writer Writer, clock Clock) (*Tracer, error)
NewWithDependencies creates a tracer with a custom writer and clock.
func (*Tracer) DroppedEventCount ¶
type TracingError ¶
TracingError reports a runtime tracing failure.
func (*TracingError) Error ¶
func (e *TracingError) Error() string
func (*TracingError) Unwrap ¶
func (e *TracingError) Unwrap() error
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
benchmarks
|
|
|
event
command
|
|
|
cmd
|
|
|
eventtrace
command
|
|
|
examples
|
|
|
basic
command
|
|
|
http-api
command
|
|
|
internal
|
|