Documentation
¶
Overview ¶
Package telemetry 提供可选的可观测性集成 包含 Aspect 切面用于工作流节点追踪,和 Agent 结构化日志
Index ¶
- type AgentLogger
- type NoOpTracer
- type OTelAgentLogger
- func (l *OTelAgentLogger) LogAgentRound(ctx context.Context, round int, toolCalls int, hasResponse bool)
- func (l *OTelAgentLogger) LogModelCall(ctx context.Context, model string, tokens int, duration time.Duration, ...)
- func (l *OTelAgentLogger) LogToolCall(ctx context.Context, toolName string, args map[string]any, ...)
- type OTelMetrics
- type OTelSpan
- type OTelTracer
- type SlogTracer
- type Span
- type SpanCode
- type Tracer
- type WorkflowAspect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentLogger ¶
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 ¶
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{}
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)
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 ¶
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) RecordError ¶
func (*OTelSpan) SetAttribute ¶
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 创建追踪器
type SlogTracer ¶
SlogTracer 基于 slog 的简单追踪器 不需要外部依赖,适合开发和调试
func NewSlogTracer ¶
func NewSlogTracer(logger *slog.Logger) *SlogTracer
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 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