base

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrHeader        = "http.header"
	AttrProtocol      = "http.protocol"
	AttrRequestMethod = "http.request.method"
	AttrRequestUrl    = "http.request.url"
	AttrUserAgent     = "http.user.agent"
)
View Source
const (
	DefaultBucketBatch       = 100
	DefaultBucketConcurrency = 3
	DefaultBucketFrequency   = 350
	DefaultBucketSize        = 3000
)
View Source
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"
)

func (Adapter) Generator

func (o Adapter) Generator() Adapter

Generator generates a valid adapter.

func (Adapter) String

func (o Adapter) String() string

String returns the adapter name.

type Attr

type Attr map[string]any

Attr is a key-value pair for span attributes.

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

func NewBucket[T any](name string, handler func([]T)) *Bucket[T]

NewBucket creates a new bucket instance for memory data storage.

return NewBucket("span", handler)
return NewBucket("logger", handler)

func (*Bucket[T]) Add

func (o *Bucket[T]) Add(items ...T)

Add adds a list items into memory.

func (*Bucket[T]) Name

func (o *Bucket[T]) Name() string

Name returns the bucket name.

func (*Bucket[T]) SetBatch

func (o *Bucket[T]) SetBatch(batch int)

SetBatch sets the batch size for each pop.

func (*Bucket[T]) SetConcurrency

func (o *Bucket[T]) SetConcurrency(concurrency int32)

SetConcurrency sets the concurrency for log or span reporter.

func (*Bucket[T]) SetFrequency

func (o *Bucket[T]) SetFrequency(frequency int)

SetFrequency sets the frequency for log or span reporter.

func (*Bucket[T]) SetSize

func (o *Bucket[T]) SetSize(size int)

SetSize sets the maximum count messages for memory storage.

func (*Bucket[T]) Start

func (o *Bucket[T]) Start()

Start starts the bucket handler in a goroutine.

func (*Bucket[T]) Stop

func (o *Bucket[T]) Stop()

Stop stops the bucket handler.

func (*Bucket[T]) Wait

func (o *Bucket[T]) Wait()

Wait until memory data is empty and processes are done.

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.

func (*Item) Copy

func (o *Item) Copy() *Item

Copy an item with current fields value.

func (*Item) JsonField

func (o *Item) JsonField() string

JsonField converts the log fields to json string.

func (*Item) Release

func (o *Item) Release()

Release put the item entry to pool.

func (*Item) String

func (o *Item) String() (str string)

String converts the log entry as a string with stack traces.

func (*Item) With

func (o *Item) With(ctx context.Context) *Item

With bind context on entry.

type Level

type Level string

Level is a type name of log level.

const (
	LevelDebug Level = "DEBUG"
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelFatal Level = "FATAL"
)

func (Level) Generator

func (o Level) Generator() Level

Generator generates a valid level.

func (Level) IsDebug

func (o Level) IsDebug() bool

func (Level) IsError

func (o Level) IsError() bool

func (Level) IsFatal

func (o Level) IsFatal() bool

func (Level) IsInfo

func (o Level) IsInfo() bool

func (Level) IsWarn

func (o Level) IsWarn() bool

func (Level) String

func (o Level) String() string

String returns the level name.

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 NewSpanId

func NewSpanId() *SpanId

NewSpanId creates a new span id.

func NewSpanIdWithHex

func NewSpanIdWithHex(s string) *SpanId

NewSpanIdWithHex creates a new span id from hex string.

func (*SpanId) Byte

func (o *SpanId) Byte() []byte

Byte returns the span id as a byte array.

func (*SpanId) String

func (o *SpanId) String() string

String returns the span id as a string.

type SpanWithAttr

type SpanWithAttr interface {
	// GetAttr
	// returns the attr of the span.
	GetAttr() Attr

	// SetAttr
	// sets the attr of the span.
	SetAttr(key string, val any)
}

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 Stack

type Stack interface {
	String() string
}

Stack is a component for call stack.

type StackItem

type StackItem struct {
	Callee string
	Line   int
	Path   string
}

StackItem is a component for call stack item.

func (*StackItem) Parse

func (o *StackItem) Parse(s string) *StackItem

func (*StackItem) Render

func (o *StackItem) Render(i int) string

type TraceId

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

TraceId is a component of a trace.

func NewTraceId

func NewTraceId() *TraceId

NewTraceId creates a new trace id.

func NewTraceIdWithHex

func NewTraceIdWithHex(s string) *TraceId

NewTraceIdWithHex creates a new trace id with hex string.

func (*TraceId) Byte

func (o *TraceId) Byte() []byte

Byte returns the trace id as a byte array.

func (*TraceId) String

func (o *TraceId) String() string

String returns the trace id as a string.

type Tracer

type Tracer string

Tracer is a type name of trace reporter.

const (
	TracerJaeger Tracer = "jaeger"
	TracerZipkin Tracer = "zipkin"
)

func (Tracer) Disabled

func (o Tracer) Disabled() bool

Disabled return true if the configured tracer is empty or not matched.

func (Tracer) Generator

func (o Tracer) Generator() Tracer

Generator generates a valid tracer.

func (Tracer) String

func (o Tracer) String() string

Strings returns the tracer name.

type Tracing

type Tracing struct {
	ParentSpanId       *SpanId
	ParentSpanPosition int32
	SpanId             *SpanId
	SpanPosition       int32
	TraceId            *TraceId
}

Tracing is a component of a trace.

func NewTracing

func NewTracing() *Tracing

NewTracing creates a new tracing.

func NewTracingWithHex

func NewTracingWithHex(tid, sid string, position int32) *Tracing

NewTracingWithHex creates a new tracing with hex string.

func (*Tracing) Child

func (o *Tracing) Child() *Tracing

Child creates a child tracing.

func (*Tracing) Increment

func (o *Tracing) Increment() (before, after int32)

Increment increments the span position.

Jump to

Keyboard shortcuts

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