Documentation
¶
Index ¶
- func AddDefaultSink(s Sink)
- func Emit(e Event)
- func EmitTo(tr *Tracer, e Event)
- func NewContainerID() string
- func ResetForTest()
- func TraceEnabled() bool
- func TraceToAttrs(args ...any) map[string]any
- func WithContainer(ctx context.Context, containerID string) context.Context
- func WithContainerTracer(ctx context.Context, containerID string, tr *Tracer) context.Context
- type Event
- type FileSink
- type MemorySink
- type Query
- type ReadResult
- type Sink
- type Span
- type Tracer
- type TreeNode
- type TreeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDefaultSink ¶ added in v2.2.0
func AddDefaultSink(s Sink)
AddDefaultSink 向全局 Tracer 追加事件订阅 sink。
func NewContainerID ¶ added in v2.2.0
func NewContainerID() string
NewContainerID 生成容器标识(16 hex 随机,rand 失败回退计数器)。
func ResetForTest ¶
func ResetForTest()
ResetForTest clears in-memory trace state. Intended for tests only.
func WithContainer ¶ added in v2.2.0
ctxState 携带容器标识与可选 Tracer,经 ctx 传递并被嵌套 span 继承。 WithContainer 把容器标识写入 ctx:之后创建的 span 事件都会携带该标识。
Types ¶
type Event ¶
type Event struct {
ID int64 `json:"id"`
ContainerID string `json:"container_id,omitempty"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
ParentSpanID string `json:"parent_span_id,omitempty"`
Operation string `json:"operation,omitempty"`
Phase string `json:"phase,omitempty"`
Event string `json:"event,omitempty"`
Status string `json:"status,omitempty"`
Component string `json:"component,omitempty"`
ProviderFunction string `json:"provider_function,omitempty"`
OutputType string `json:"output_type,omitempty"`
InputType string `json:"input_type,omitempty"`
InputTypes []string `json:"input_types,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
TimedOut bool `json:"timed_out,omitempty"`
DurationNs int64 `json:"duration_ns,omitempty"`
OccurredAt int64 `json:"occurred_at_unix_nano"`
Attrs map[string]any `json:"attrs,omitempty"`
}
Event 是统一 trace 事件结构。
type FileSink ¶
type FileSink struct {
// contains filtered or unexported fields
}
func NewFileSink ¶
type MemorySink ¶
type MemorySink struct {
// contains filtered or unexported fields
}
MemorySink 用于 API 查询,并增量维护每条 trace 的调用树索引。
func NewMemorySink ¶
func NewMemorySink(max int) *MemorySink
func (*MemorySink) Query ¶
func (m *MemorySink) Query(q Query) ReadResult
func (*MemorySink) QueryTree ¶ added in v2.2.0
func (m *MemorySink) QueryTree(traceID string) TreeResult
QueryTree 组装一次 trace 的调用树;孤儿 span(父已驱逐)按根处理。
func (*MemorySink) Write ¶
func (m *MemorySink) Write(e Event)
type Query ¶
type Query struct {
TraceID string
ContainerID string
Operation string
Status string
Event string
Component string
Provider string
OutputType string
Search string
Limit int
BeforeID int64
SinceUnixNs int64
UntilUnixNs int64
}
Query 控制 trace 查询过滤。
func ParseQueryFromMap ¶
ParseQueryFromMap 从 query 参数 map 解析过滤条件。
type ReadResult ¶
type ReadResult struct {
Enabled bool `json:"enabled"`
Total int `json:"total"`
Returned int `json:"returned"`
NextBefore int64 `json:"next_before_id,omitempty"`
Records []Event `json:"records"`
}
ReadResult 是 trace 查询返回结构。
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
func (*Tracer) QueryEvents ¶ added in v2.2.0
func (t *Tracer) QueryEvents(q Query) ReadResult
QueryEvents 查询该 Tracer 内存 sink 中的事件;nil 回落全局。
func (*Tracer) QueryTree ¶ added in v2.2.0
func (t *Tracer) QueryTree(traceID string) TreeResult
QueryTree 返回该 Tracer 内存 sink 中的调用树;nil 回落全局。
type TreeNode ¶ added in v2.2.0
type TreeNode struct {
Event Event `json:"event"`
End *Event `json:"end,omitempty"`
Children []*TreeNode `json:"children"`
}
TreeNode 是调用树节点:Event 为 span.start,End 为 span.end(存在时)。
type TreeResult ¶ added in v2.2.0
type TreeResult struct {
Enabled bool `json:"enabled"`
TraceID string `json:"trace_id"`
Total int `json:"total"`
Roots []*TreeNode `json:"roots"`
}
TreeResult 是一次 trace 的调用树。
func QueryTree ¶ added in v2.2.0
func QueryTree(traceID string) TreeResult
QueryTree 查询全局内存 sink 中的调用树。