Documentation
¶
Index ¶
- Constants
- type Adapter
- type Attr
- type Bucket
- func (o *Bucket[T]) Add(items ...T)
- func (o *Bucket[T]) Name() string
- func (o *Bucket[T]) SetBatch(batch int)
- func (o *Bucket[T]) SetConcurrency(concurrency int32)
- func (o *Bucket[T]) SetFrequency(frequency int)
- func (o *Bucket[T]) SetSize(size int)
- func (o *Bucket[T]) Start()
- func (o *Bucket[T]) Stop()
- func (o *Bucket[T]) Wait()
- type Item
- type Level
- type Logger
- type LoggerFormatter
- type Reporter
- type ReporterFormatter
- type Span
- type SpanId
- type SpanWithAttr
- type SpanWithLogger
- type Stack
- type StackItem
- type TraceId
- type Tracer
- type Tracing
Constants ¶
const ( AttrHeader = "http.header" AttrProtocol = "http.protocol" AttrRequestMethod = "http.request.method" AttrRequestUrl = "http.request.url" AttrUserAgent = "http.user.agent" )
const ( DefaultBucketBatch = 100 DefaultBucketConcurrency = 3 DefaultBucketFrequency = 350 DefaultBucketSize = 3000 )
const (
TracingOnContext = "__SpanContext__"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter string
Adapter is a type name for logger writer.
const ( // AdapterElasticsearch // publish log messages to elasticsearch. AdapterElasticsearch Adapter = "elastic" // AdapterFile // write log messages to local files. AdapterFile Adapter = "file" // AdapterKafka // publish log messages to kafka. AdapterKafka Adapter = "kafka" // AdapterTerm // send log messages to terminal. AdapterTerm Adapter = "term" )
type Bucket ¶
type Bucket[T any] struct { // contains filtered or unexported fields }
Bucket is a component that stores data in memory for asynchronous processing.
func NewBucket ¶
NewBucket creates a new bucket instance for memory data storage.
return NewBucket("span", handler) return NewBucket("logger", handler)
func (*Bucket[T]) SetConcurrency ¶
SetConcurrency sets the concurrency for log or span reporter.
func (*Bucket[T]) SetFrequency ¶
SetFrequency sets the frequency for log or span reporter.
type Item ¶
type Item struct { Field map[string]any Level Level Text string Time time.Time Stack Stack SpanId, ParentSpanId *SpanId SpanPosition, ParentSpanPosition int32 TraceId *TraceId }
Item is a component from a log entry.
func NewItem ¶
func NewItem(ctx context.Context, field map[string]any, level Level, format string, args ...any) *Item
NewItem creates a new item entry based on log level and contents.
type Logger ¶
type Logger interface { // GetBucket // returns the bucket instance. GetBucket() *Bucket[*Item] // GetFormatter // returns the formatter instance. GetFormatter() LoggerFormatter // Log // report logging item. Log(item *Item) // SetFormatter // sets the formatter instance. SetFormatter(formatter LoggerFormatter) }
Logger is an interface for logging adapted for follow adapters.
- Elasticsearch
- File
- Kafka
- Term
type LoggerFormatter ¶
type LoggerFormatter interface { // Format // formats the log item to bytes. Format(item *Item) []byte }
LoggerFormatter is an interface for formatting log.
type Reporter ¶
type Reporter interface { // GetBucket // returns the bucket instance. GetBucket() *Bucket[Span] // SetFormatter // returns the formatter instance. SetFormatter(formatter ReporterFormatter) // Publish // publishes the spans to reporter. Publish(span ...Span) }
Reporter is an interface for trace reporter.
type ReporterFormatter ¶
type ReporterFormatter interface { // Format // formats the spans to bytes. Format(spans []Span) (body []byte) }
ReporterFormatter is an interface for formating the span.
type Span ¶
type Span interface { // Child // creates a child span on the span. Child(name string) Span // Context // returns the context of the span. Context() context.Context // Duration // returns the duration of the span. Duration() time.Duration // End // ends the span. End() // EndTime // returns the end time of the span. EndTime() time.Time // Logs // returns the logs of the span. Logs() []*Item // Name // returns the name of the span. Name() string // Release // put the span to the pool. Release() // StartTime // returns the start time of the span. StartTime() time.Time // Tracing // returns the tracing component of the span. Tracing() *Tracing SpanWithAttr SpanWithLogger }
Span is an interface for call chain span.
type SpanId ¶
type SpanId struct {
// contains filtered or unexported fields
}
SpanId is a component of a trace.
func NewSpanIdWithHex ¶
NewSpanIdWithHex creates a new span id from hex string.
type SpanWithAttr ¶
type SpanWithLogger ¶
type SpanWithLogger interface { // Debug // send debug level log. Debug(format string, args ...any) // Info // send info level log. Info(format string, args ...any) // Warn // send warn level log. Warn(format string, args ...any) // Error // send error level log. Error(format string, args ...any) // Fatal // send fatal level log. Fatal(format string, args ...any) }
type TraceId ¶
type TraceId struct {
// contains filtered or unexported fields
}
TraceId is a component of a trace.
func NewTraceIdWithHex ¶
NewTraceIdWithHex creates a new trace id with hex string.
type Tracer ¶
type Tracer string
Tracer is a type name of trace reporter.