common

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 19 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 (
	ContextKey = "__GO_LIB_LOG_TRACING__"
)

Variables

This section is empty.

Functions

func AttachRequest

func AttachRequest(ctx context.Context, req *http.Request)

AttachRequest 向 <http.Request> 添加兼容 OpenTracing 的 <common.Tracing> 参数.

func GetContextHeader

func GetContextHeader(ctx context.Context) http.Header

GetContextHeader 从 <context.Context> 提取 <http.Header> 参数.

func NewContext

func NewContext(cts ...context.Context) context.Context

NewContext 创建上下文.

func NewContextWithHeader added in v1.1.5

func NewContextWithHeader(header http.Header) context.Context

func SetContextTracing

func SetContextTracing(ctx context.Context, tracing Tracing) context.Context

SetContextTracing 设置 <common.Tracing> 到 <context.Context>.

Types

type Attr

type Attr map[string]any

Attr 属性参数.

func (Attr) Count

func (o Attr) Count() int

func (Attr) Set

func (o Attr) Set(key string, value any)

func (Attr) SetHeader

func (o Attr) SetHeader(val any)

func (Attr) SetProtocol

func (o Attr) SetProtocol(val any)

func (Attr) SetRequestMethod

func (o Attr) SetRequestMethod(val any)

func (Attr) SetRequestUrl

func (o Attr) SetRequestUrl(val any)

func (Attr) SetUserAgent

func (o Attr) SetUserAgent(val any)

func (Attr) Unset

func (o Attr) Unset(key string)

type Bucket

type Bucket[T any] interface {
	Add(list ...T)
	Count() (count int)
	GetBatch() (batch int)
	GetConcurrency() (concurrency int32)
	GetFrequency() (frequency int)
	Name() string
	SetBatch(batch int)
	SetConcurrency(concurrency int32)
	SetFrequency(frequency int)
	Start()
	Stop() Bucket[T]
	Wait()
}

func NewBucket

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

NewBucket 创建数据桶.

type DebuggerManager added in v1.1.1

type DebuggerManager interface {
	Error(format string, args ...any)
	Info(format string, args ...any)
	Fatal(format string, args ...any)
}
var (
	Debugger DebuggerManager
)

type Entity

type Entity struct {
	Level     base.Level `json:"level"`
	Message   string     `json:"message"`
	Time      string     `json:"time"`
	TimeMicro int64      `json:"time_micro"`

	Stack string `json:"stack,omitempty"`

	TraceId            string `json:"trace_id,omitempty"`
	SpanId             string `json:"span_id,omitempty"`
	SpanPosition       int32  `json:"span_position,omitempty"`
	ParentSpanId       string `json:"parent_span_id,omitempty"`
	ParentSpanPosition int32  `json:"parent_span_position,omitempty"`

	Pid              int      `json:"pid,omitempty"`
	ServiceAddresses []string `json:"service_addresses,omitempty"`
	ServiceHost      string   `json:"service_host,omitempty"`
	ServicePort      int      `json:"service_port,omitempty"`
	ServiceName      string   `json:"service_name,omitempty"`
	ServiceVersion   string   `json:"service_version,omitempty"`
}

Entity 日志实体.

func NewEntity

func NewEntity(item Item) *Entity

NewEntity 取出实例.

func NewEntityWithBody added in v1.1.1

func NewEntityWithBody(body []byte) *Entity

func (*Entity) Byte

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

Byte 转成 byte 列表.

func (*Entity) Release

func (o *Entity) Release()

Release 释放实例.

func (*Entity) String

func (o *Entity) String() string

String 转成 string 文本.

type Generator

type Generator interface {
	// Convert
	// converts a byte list to hex string
	Convert(bs []byte) string

	// Decode
	// hex string to byte list.
	Decode(str string) (b []byte)

	// Make
	// a byte list with given length
	//
	//   Generate.Make(8)
	//   Generate.Make(16)
	Make(n int) (b []byte)
}

Generator is a tool use to generate trace and span identify.

func NewGenerator

func NewGenerator() Generator

type Item

type Item interface {
	Copy() Item
	Level() base.Level
	Message() string
	ParentSpan() (SpanId, int32)
	Release()
	Span() (SpanId, int32)
	Stack() Stack
	String() string
	Time() time.Time
	TraceId() TraceId
}

Item 日志条目.

func NewItem

func NewItem(ctx context.Context, level base.Level, message string) Item

NewItem 取出池内对象,并初始化.

type LoggingFormatter added in v1.1.1

type LoggingFormatter interface {
	ToByte(item Item) []byte
	ToString(item Item) string
}

type LoggingManager added in v1.1.1

type LoggingManager interface {
	GetPlugin() (plugin LoggingPlugin)
	Log(ctx context.Context, level base.Level, message string)
	Send(items ...Item)
	SetPlugin(plugin LoggingPlugin)
	Wait()
}

type LoggingPlugin added in v1.1.1

type LoggingPlugin interface {
	GetFormatter() (formatter LoggingFormatter)
	GetWriter() (formatter LoggingWriter)
	SetFormatter(formatter LoggingFormatter)
	SetWriter(writer LoggingWriter)
	Sync() bool
	Write(items []Item) (err error)
}

type LoggingWriter added in v1.1.1

type LoggingWriter interface {
	Write(formatter LoggingFormatter, items []Item) (err error)
}

type Span

type Span interface {
	Child(format string, args ...any) Span
	End()
	Release()

	SpanWithGetter
	SpanWithLogger
}

type SpanFormatter

type SpanFormatter interface {
	ToByte(span Span) []byte
	ToString(span Span) string
}

type SpanId

type SpanId interface {
	Byte() []byte
	String() string
}

SpanId 链路跨度标识.

func NewSpanId

func NewSpanId() SpanId

NewSpanId 创建随机链路跨度标识.

func NewSpanIdWithHex

func NewSpanIdWithHex(s string) SpanId

NewSpanIdWithHex 基于指定值创建链路跨度标识.

type SpanManager added in v1.1.1

type SpanManager interface {
	GetPlugin() (plugin SpanPlugin)
	Send(span Span)
	SetPlugin(plugin SpanPlugin)
	Wait()
}

type SpanPlugin

type SpanPlugin interface {
	GetFormatter() (formatter SpanFormatter)
	GetReporter() (reporter SpanReporter)
	Report(spans []Span) (err error)
	SetFormatter(formatter SpanFormatter)
	SetReporter(reporter SpanReporter)
}

type SpanReporter added in v1.1.1

type SpanReporter interface {
	// Report
	// 上报数据.
	Report(formatter SpanFormatter, spans []Span) (err error)
}

SpanReporter 上报跟踪数据, 应用于 Jaeger, Zipkin 等.

type SpanWithGetter added in v1.1.1

type SpanWithGetter interface {
	GetAttr() Attr
	GetContext() context.Context
	GetEndTime() time.Time
	GetDuration() time.Duration
	GetLogs() []Item
	GetName() string
	GetStartTime() time.Time
	GetTracing() Tracing
}

SpanWithGetter 读取参数.

type SpanWithLogger added in v1.1.1

type SpanWithLogger interface {
	Debug(format string, args ...any)
	Info(format string, args ...any)
	Warn(format string, args ...any)
	Error(format string, args ...any)
	Fatal(format string, args ...any)
}

SpanWithLogger 操作日志.

type Stack

type Stack interface {
	String() string
}

Stack is a component for call stack.

func NewStack

func NewStack() 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 interface {
	Byte() []byte
	String() string
}

TraceId 链路追踪标识.

func NewTraceId

func NewTraceId() TraceId

NewTraceId 创建随机链路追踪标识.

func NewTraceIdWithHex

func NewTraceIdWithHex(s string) TraceId

NewTraceIdWithHex 基于指定值创建链路跟踪标识.

type Tracing

type Tracing interface {
	// Child
	// 创建子链路追踪标识接口.
	//
	// 基于当前 Tracing, 创建子 Tracing 实例, 维护本节与上级的跟踪跨度ID.
	Child() Tracing

	// GetParent
	// 读取上级链路跟踪ID与点位.
	GetParent() (SpanId, int32)

	// GetParentSpanId
	// 读取上级链路跟踪ID.
	GetParentSpanId() SpanId

	// GetSpan
	// 读取链路跟踪跨度ID与点位.
	GetSpan() (SpanId, int32)

	// GetSpanAndIncrement
	// 取本级点位, 并递增至下个节点点位.
	GetSpanAndIncrement() (SpanId, int32)

	// GetSpanId
	// 读取链路跟踪跨度ID.
	GetSpanId() SpanId

	// GetTraceId
	// 读取链路追踪ID.
	GetTraceId() TraceId
}

Tracing 链路追踪标识接口.

func GetContextTracing

func GetContextTracing(ctx context.Context) Tracing

GetContextTracing 从 <context.Context> 提取 <common.Tracing>.

func NewTracing

func NewTracing() Tracing

NewTracing 创建根级追踪.

func NewTracingWithContext

func NewTracingWithContext(ctx context.Context) Tracing

NewTracingWithContext 创建子级追踪.

func NewTracingWithHeader

func NewTracingWithHeader(header http.Header) Tracing

func NewTracingWithRequest

func NewTracingWithRequest(request *http.Request) Tracing

Jump to

Keyboard shortcuts

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