telemetry

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package telemetry 提供可选的可观测性集成 包含 Aspect 切面用于工作流节点追踪,和 Agent 结构化日志

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentLogger

type AgentLogger struct {
	Logger *slog.Logger
}

AgentLogger Agent 操作日志

func NewAgentLogger

func NewAgentLogger(logger *slog.Logger) *AgentLogger

func (*AgentLogger) LogAgentRound

func (l *AgentLogger) LogAgentRound(round int, toolCalls int, hasResponse bool)

LogAgentRound 记录 Agent 循环轮次

func (*AgentLogger) LogModelCall

func (l *AgentLogger) LogModelCall(model string, tokens int, duration time.Duration, err error)

LogModelCall 记录模型调用

func (*AgentLogger) LogToolCall

func (l *AgentLogger) LogToolCall(toolName string, args map[string]any, duration time.Duration, err error)

LogToolCall 记录工具调用

type NoOpTracer

type NoOpTracer struct{}

func (NoOpTracer) Start

func (NoOpTracer) Start(ctx context.Context, name string) (context.Context, Span)

type OTelAgentLogger

type OTelAgentLogger struct {
	*AgentLogger
	// contains filtered or unexported fields
}

OTelAgentLogger 将 Agent 操作同时输出到 slog 日志、OTel span 和 metrics

func NewOTelAgentLogger

func NewOTelAgentLogger(tracer *OTelTracer, metrics *OTelMetrics) *OTelAgentLogger

NewOTelAgentLogger 创建统一日志器

func (*OTelAgentLogger) LogAgentRound

func (l *OTelAgentLogger) LogAgentRound(ctx context.Context, round int, toolCalls int, hasResponse bool)

LogAgentRound 记录 Agent 循环轮次(日志 + metrics)

func (*OTelAgentLogger) LogModelCall

func (l *OTelAgentLogger) LogModelCall(ctx context.Context, model string, tokens int, duration time.Duration, err error)

LogModelCall 记录模型调用(日志 + metrics)

func (*OTelAgentLogger) LogToolCall

func (l *OTelAgentLogger) LogToolCall(ctx context.Context, toolName string, args map[string]any, duration time.Duration, err error)

LogToolCall 记录工具调用(日志 + span + metrics)

type OTelMetrics

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

OTelMetrics 收集 Agent 操作指标

func NewOTelMetrics

func NewOTelMetrics(name string) (*OTelMetrics, error)

NewOTelMetrics 创建 OTel 指标收集器

func (*OTelMetrics) RecordAgentRound

func (m *OTelMetrics) RecordAgentRound(ctx context.Context)

RecordAgentRound 记录 Agent 循环轮次

func (*OTelMetrics) RecordModelCall

func (m *OTelMetrics) RecordModelCall(ctx context.Context, model string, tokens int, err error)

RecordModelCall 记录模型调用指标

func (*OTelMetrics) RecordToolCall

func (m *OTelMetrics) RecordToolCall(ctx context.Context, toolName string, duration time.Duration, err error)

RecordToolCall 记录工具调用指标

type OTelSpan

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

OTelSpan 包装 OpenTelemetry 的 trace.Span,实现 Span 接口

func (*OTelSpan) End

func (s *OTelSpan) End()

func (*OTelSpan) RecordError

func (s *OTelSpan) RecordError(err error)

func (*OTelSpan) SetAttribute

func (s *OTelSpan) SetAttribute(key string, value any)

func (*OTelSpan) SetStatus

func (s *OTelSpan) SetStatus(code SpanCode, description string)

type OTelTracer

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

OTelTracer 包装 OpenTelemetry 的 trace.Tracer,实现 Tracer 接口

func NewOTelTracer

func NewOTelTracer(name string) *OTelTracer

NewOTelTracer 创建基于 OpenTelemetry 的追踪器 name: instrumentation name,如 "github.com/Luo-root/pulse"

func NewOTelTracerWithProvider

func NewOTelTracerWithProvider(name string, provider trace.TracerProvider) *OTelTracer

NewOTelTracerWithProvider 使用指定 TracerProvider 创建追踪器

func (*OTelTracer) Start

func (t *OTelTracer) Start(ctx context.Context, name string) (context.Context, Span)

type SlogTracer

type SlogTracer struct {
	Logger *slog.Logger
}

SlogTracer 基于 slog 的简单追踪器 不需要外部依赖,适合开发和调试

func NewSlogTracer

func NewSlogTracer(logger *slog.Logger) *SlogTracer

func (*SlogTracer) Start

func (t *SlogTracer) Start(ctx context.Context, name string) (context.Context, Span)

type Span

type Span interface {
	// SetAttribute 设置属性
	SetAttribute(key string, value any)
	// SetStatus 设置状态
	SetStatus(code SpanCode, description string)
	// RecordError 记录错误
	RecordError(err error)
	// End 结束跨度
	End()
}

Span 追踪跨度

type SpanCode

type SpanCode int

SpanCode 跨度状态码

const (
	SpanOK SpanCode = iota
	SpanError
)

type Tracer

type Tracer interface {
	// Start 开始一个新跨度
	Start(ctx context.Context, name string) (context.Context, Span)
}

Tracer 追踪器接口

type WorkflowAspect

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

WorkflowAspect 工作流节点追踪切面 在每个节点执行前后记录 span

func NewWorkflowAspect

func NewWorkflowAspect(tracer Tracer) *WorkflowAspect

func (*WorkflowAspect) Around

func (a *WorkflowAspect) Around(ctx *node.AspectContext, n node.Node, next func() (map[string]any, error)) (map[string]any, error)

Jump to

Keyboard shortcuts

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