Documentation
¶
Index ¶
- func AddAttributes(span trace.Span, attrs ...attribute.KeyValue)
- func AddEvent(span trace.Span, name string, attrs ...attribute.KeyValue)
- func AgentAttributes(agentName, agentType string) []attribute.KeyValue
- func DecrementConcurrentExecutions()
- func ErrorAttributes(errorType, errorMessage string) []attribute.KeyValue
- func IncrementConcurrentExecutions()
- func LLMAttributes(model, provider string, tokens int) []attribute.KeyValue
- func MemoryAttributes(operation, memoryType string, size int) []attribute.KeyValue
- func RecordAgentError(agentName, service, errorType string)
- func RecordAgentExecution(agentName, service, status string, duration time.Duration)
- func RecordError(span trace.Span, err error)
- func RecordRemoteAgentCall(service, agentName, status string, duration time.Duration)
- func RecordRemoteAgentError(service, agentName, errorType string)
- func RecordToolCall(toolName, agentName, status string, duration time.Duration)
- func RecordToolError(toolName, agentName, errorType string)
- func StartAgentSpan(ctx context.Context, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func StartRemoteAgentSpan(ctx context.Context, service, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func StartToolSpan(ctx context.Context, toolName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func ToolAttributes(toolName, toolType string) []attribute.KeyValue
- func UpdateServiceInstances(service string, total, healthy int)
- func WrapAgent(agent agentcore.Agent, serviceName string, logger core.Logger) agentcore.Agent
- type AgentMetrics
- func (m *AgentMetrics) IncrementActiveAgents(ctx context.Context, delta int64)
- func (m *AgentMetrics) RecordAgentExecution(ctx context.Context, agentName, agentType string, durationSeconds float64, ...)
- func (m *AgentMetrics) RecordChainExecution(ctx context.Context, chainName string, steps int, durationSeconds float64, ...)
- func (m *AgentMetrics) RecordError(ctx context.Context, errorType string, attrs ...attribute.KeyValue)
- func (m *AgentMetrics) RecordLLMCall(ctx context.Context, model, provider string, tokens int, ...)
- func (m *AgentMetrics) RecordMemoryOperation(ctx context.Context, operation, memoryType string, size int, ...)
- func (m *AgentMetrics) RecordRequest(ctx context.Context, durationSeconds float64, success bool, ...)
- func (m *AgentMetrics) RecordToolCall(ctx context.Context, toolName string, durationSeconds float64, success bool)
- type AgentTracer
- func (t *AgentTracer) AddEvent(ctx context.Context, name string, attrs ...attribute.KeyValue)
- func (t *AgentTracer) GetTracer() trace.Tracer
- func (t *AgentTracer) RecordError(ctx context.Context, err error, opts ...trace.EventOption)
- func (t *AgentTracer) SetAttributes(ctx context.Context, attrs ...attribute.KeyValue)
- func (t *AgentTracer) SetStatus(ctx context.Context, code codes.Code, description string)
- func (t *AgentTracer) SpanFromContext(ctx context.Context) trace.Span
- func (t *AgentTracer) StartAgentSpan(ctx context.Context, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func (t *AgentTracer) StartChainSpan(ctx context.Context, chainName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func (t *AgentTracer) StartLLMSpan(ctx context.Context, model string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func (t *AgentTracer) StartMemorySpan(ctx context.Context, operation string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func (t *AgentTracer) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (t *AgentTracer) StartToolSpan(ctx context.Context, toolName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func (t *AgentTracer) WithSpanContext(ctx context.Context, spanName string, fn func(context.Context) error, ...) error
- type CrossServiceTracer
- func (t *CrossServiceTracer) TraceHTTPRequest(ctx context.Context, req *http.Request) (context.Context, trace.Span)
- func (t *CrossServiceTracer) TraceHTTPResponse(ctx context.Context, resp *http.Response) error
- func (t *CrossServiceTracer) TraceMessage(ctx context.Context, topic string, message []byte) (context.Context, trace.Span, *MessageCarrier)
- type DistributedTracer
- func (t *DistributedTracer) ExtractContext(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
- func (t *DistributedTracer) InjectContext(ctx context.Context, carrier propagation.TextMapCarrier) error
- func (t *DistributedTracer) StartRemoteSpan(ctx context.Context, name string, carrier propagation.TextMapCarrier) (context.Context, trace.Span)
- type HTTPCarrier
- type InstrumentedAgent
- func (i *InstrumentedAgent) Batch(ctx context.Context, inputs []*agentcore.AgentInput) ([]*agentcore.AgentOutput, error)
- func (i *InstrumentedAgent) Capabilities() []string
- func (i *InstrumentedAgent) Description() string
- func (i *InstrumentedAgent) Invoke(ctx context.Context, input *agentcore.AgentInput) (*agentcore.AgentOutput, error)
- func (i *InstrumentedAgent) Name() string
- func (i *InstrumentedAgent) Pipe(next agentcore.Runnable[*agentcore.AgentOutput, any]) agentcore.Runnable[*agentcore.AgentInput, any]
- func (i *InstrumentedAgent) Stream(ctx context.Context, input *agentcore.AgentInput) (<-chan agentcore.StreamChunk[*agentcore.AgentOutput], error)
- func (i *InstrumentedAgent) WithCallbacks(callbacks ...agentcore.Callback) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
- func (i *InstrumentedAgent) WithConfig(config agentcore.RunnableConfig) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
- type MessageCarrier
- type Metrics
- type TelemetryConfig
- type TelemetryProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAttributes ¶
AddAttributes 添加属性到 span
func AgentAttributes ¶
AgentAttributes 创建 Agent 属性
func DecrementConcurrentExecutions ¶
func DecrementConcurrentExecutions()
DecrementConcurrentExecutions 减少并发执行数
func ErrorAttributes ¶
ErrorAttributes 创建错误属性
func IncrementConcurrentExecutions ¶
func IncrementConcurrentExecutions()
IncrementConcurrentExecutions 增加并发执行数
func LLMAttributes ¶
LLMAttributes 创建 LLM 属性
func MemoryAttributes ¶
MemoryAttributes 创建内存属性
func RecordAgentError ¶
func RecordAgentError(agentName, service, errorType string)
RecordAgentError 记录 Agent 错误
func RecordAgentExecution ¶
RecordAgentExecution 记录 Agent 执行
func RecordRemoteAgentCall ¶
RecordRemoteAgentCall 记录远程 Agent 调用
func RecordRemoteAgentError ¶
func RecordRemoteAgentError(service, agentName, errorType string)
RecordRemoteAgentError 记录远程 Agent 错误
func RecordToolCall ¶
RecordToolCall 记录工具调用
func RecordToolError ¶
func RecordToolError(toolName, agentName, errorType string)
RecordToolError 记录工具错误
func StartAgentSpan ¶
func StartAgentSpan(ctx context.Context, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartAgentSpan 启动 Agent span
func StartRemoteAgentSpan ¶
func StartRemoteAgentSpan(ctx context.Context, service, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartRemoteAgentSpan 启动远程 Agent span
func StartToolSpan ¶
func StartToolSpan(ctx context.Context, toolName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartToolSpan 启动工具 span
func ToolAttributes ¶
ToolAttributes 创建工具属性
func UpdateServiceInstances ¶
UpdateServiceInstances 更新服务实例数量
Types ¶
type AgentMetrics ¶
type AgentMetrics struct {
// contains filtered or unexported fields
}
AgentMetrics Agent 指标
func NewAgentMetrics ¶
func NewAgentMetrics(provider *TelemetryProvider, name string) (*AgentMetrics, error)
NewAgentMetrics 创建指标
func (*AgentMetrics) IncrementActiveAgents ¶
func (m *AgentMetrics) IncrementActiveAgents(ctx context.Context, delta int64)
IncrementActiveAgents 增加活跃 Agent
func (*AgentMetrics) RecordAgentExecution ¶
func (m *AgentMetrics) RecordAgentExecution(ctx context.Context, agentName, agentType string, durationSeconds float64, success bool)
RecordAgentExecution 记录 Agent 执行 (便利方法)
func (*AgentMetrics) RecordChainExecution ¶
func (m *AgentMetrics) RecordChainExecution(ctx context.Context, chainName string, steps int, durationSeconds float64, success bool)
RecordChainExecution 记录链执行
func (*AgentMetrics) RecordError ¶
func (m *AgentMetrics) RecordError(ctx context.Context, errorType string, attrs ...attribute.KeyValue)
RecordError 记录错误
func (*AgentMetrics) RecordLLMCall ¶
func (m *AgentMetrics) RecordLLMCall(ctx context.Context, model, provider string, tokens int, durationSeconds float64, success bool)
RecordLLMCall 记录 LLM 调用
func (*AgentMetrics) RecordMemoryOperation ¶
func (m *AgentMetrics) RecordMemoryOperation(ctx context.Context, operation, memoryType string, size int, durationSeconds float64, success bool)
RecordMemoryOperation 记录内存操作
func (*AgentMetrics) RecordRequest ¶
func (m *AgentMetrics) RecordRequest(ctx context.Context, durationSeconds float64, success bool, attrs ...attribute.KeyValue)
RecordRequest 记录请求
func (*AgentMetrics) RecordToolCall ¶
func (m *AgentMetrics) RecordToolCall(ctx context.Context, toolName string, durationSeconds float64, success bool)
RecordToolCall 记录工具调用
type AgentTracer ¶
type AgentTracer struct {
// contains filtered or unexported fields
}
AgentTracer Agent 追踪器
func NewAgentTracer ¶
func NewAgentTracer(provider *TelemetryProvider, name string) *AgentTracer
NewAgentTracer 创建 Agent 追踪器
func (*AgentTracer) GetTracer ¶
func (t *AgentTracer) GetTracer() trace.Tracer
GetTracer 获取底层 tracer
func (*AgentTracer) RecordError ¶
func (t *AgentTracer) RecordError(ctx context.Context, err error, opts ...trace.EventOption)
RecordError 记录错误
func (*AgentTracer) SetAttributes ¶
func (t *AgentTracer) SetAttributes(ctx context.Context, attrs ...attribute.KeyValue)
SetAttributes 设置属性
func (*AgentTracer) SpanFromContext ¶
func (t *AgentTracer) SpanFromContext(ctx context.Context) trace.Span
SpanFromContext 从上下文获取 Span
func (*AgentTracer) StartAgentSpan ¶
func (t *AgentTracer) StartAgentSpan(ctx context.Context, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartAgentSpan 启动 Agent 执行 span
func (*AgentTracer) StartChainSpan ¶
func (t *AgentTracer) StartChainSpan(ctx context.Context, chainName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartChainSpan 启动链执行 span
func (*AgentTracer) StartLLMSpan ¶
func (t *AgentTracer) StartLLMSpan(ctx context.Context, model string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartLLMSpan 启动 LLM 调用 span
func (*AgentTracer) StartMemorySpan ¶
func (t *AgentTracer) StartMemorySpan(ctx context.Context, operation string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartMemorySpan 启动内存操作 span
func (*AgentTracer) StartSpan ¶
func (t *AgentTracer) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartSpan 开始 Span
type CrossServiceTracer ¶
type CrossServiceTracer struct {
// contains filtered or unexported fields
}
CrossServiceTracer 跨服务追踪器
func NewCrossServiceTracer ¶
func NewCrossServiceTracer(serviceName string) *CrossServiceTracer
NewCrossServiceTracer 创建跨服务追踪器
func (*CrossServiceTracer) TraceHTTPRequest ¶
func (t *CrossServiceTracer) TraceHTTPRequest(ctx context.Context, req *http.Request) (context.Context, trace.Span)
TraceHTTPRequest 追踪 HTTP 请求
func (*CrossServiceTracer) TraceHTTPResponse ¶
TraceHTTPResponse 追踪 HTTP 响应
func (*CrossServiceTracer) TraceMessage ¶
func (t *CrossServiceTracer) TraceMessage(ctx context.Context, topic string, message []byte) (context.Context, trace.Span, *MessageCarrier)
TraceMessage 追踪消息(NATS/Kafka 等)
type DistributedTracer ¶
type DistributedTracer struct {
// contains filtered or unexported fields
}
DistributedTracer 分布式追踪器
func NewDistributedTracer ¶
func NewDistributedTracer() *DistributedTracer
NewDistributedTracer 创建分布式追踪器
func (*DistributedTracer) ExtractContext ¶
func (t *DistributedTracer) ExtractContext(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
ExtractContext 从 carrier 提取上下文
func (*DistributedTracer) InjectContext ¶
func (t *DistributedTracer) InjectContext(ctx context.Context, carrier propagation.TextMapCarrier) error
InjectContext 注入上下文到 carrier
func (*DistributedTracer) StartRemoteSpan ¶
func (t *DistributedTracer) StartRemoteSpan(ctx context.Context, name string, carrier propagation.TextMapCarrier) (context.Context, trace.Span)
StartRemoteSpan 开始远程 Span
type HTTPCarrier ¶
type HTTPCarrier struct {
// contains filtered or unexported fields
}
HTTPCarrier HTTP 载体
func NewHTTPCarrier ¶
func NewHTTPCarrier(headers http.Header) *HTTPCarrier
NewHTTPCarrier 创建 HTTP 载体
type InstrumentedAgent ¶
type InstrumentedAgent struct {
// contains filtered or unexported fields
}
InstrumentedAgent 带可观测性的 Agent 包装器 自动记录指标、日志和追踪
func NewInstrumentedAgent ¶
func NewInstrumentedAgent(agent agentcore.Agent, serviceName string, logger core.Logger) *InstrumentedAgent
NewInstrumentedAgent 创建带可观测性的 Agent
func (*InstrumentedAgent) Batch ¶
func (i *InstrumentedAgent) Batch(ctx context.Context, inputs []*agentcore.AgentInput) ([]*agentcore.AgentOutput, error)
Batch 批量执行 Agent 并自动记录可观测性数据
func (*InstrumentedAgent) Capabilities ¶
func (i *InstrumentedAgent) Capabilities() []string
Capabilities 返回 Agent 能力
func (*InstrumentedAgent) Description ¶
func (i *InstrumentedAgent) Description() string
Description 返回 Agent 描述
func (*InstrumentedAgent) Invoke ¶
func (i *InstrumentedAgent) Invoke(ctx context.Context, input *agentcore.AgentInput) (*agentcore.AgentOutput, error)
Invoke 执行 Agent 并自动记录可观测性数据
func (*InstrumentedAgent) Pipe ¶
func (i *InstrumentedAgent) Pipe(next agentcore.Runnable[*agentcore.AgentOutput, any]) agentcore.Runnable[*agentcore.AgentInput, any]
Pipe 连接到另一个 Runnable(委托给内部 agent)
func (*InstrumentedAgent) Stream ¶
func (i *InstrumentedAgent) Stream(ctx context.Context, input *agentcore.AgentInput) (<-chan agentcore.StreamChunk[*agentcore.AgentOutput], error)
Stream 流式执行 Agent 并自动记录可观测性数据
func (*InstrumentedAgent) WithCallbacks ¶
func (i *InstrumentedAgent) WithCallbacks(callbacks ...agentcore.Callback) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
WithCallbacks 添加回调处理器(委托给内部 agent)
func (*InstrumentedAgent) WithConfig ¶
func (i *InstrumentedAgent) WithConfig(config agentcore.RunnableConfig) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
WithConfig 配置 Agent(委托给内部 agent)
type MessageCarrier ¶
type MessageCarrier struct {
// contains filtered or unexported fields
}
MessageCarrier 消息载体(用于消息队列)
func NewMessageCarrier ¶
func NewMessageCarrier(metadata map[string]string) *MessageCarrier
NewMessageCarrier 创建消息载体
func (*MessageCarrier) GetMetadata ¶
func (c *MessageCarrier) GetMetadata() map[string]string
GetMetadata 获取完整元数据
type Metrics ¶
type Metrics struct {
// Agent 执行指标
AgentExecutions *prometheus.CounterVec
AgentDuration *prometheus.HistogramVec
AgentErrors *prometheus.CounterVec
// 工具调用指标
ToolCalls *prometheus.CounterVec
ToolDuration *prometheus.HistogramVec
ToolErrors *prometheus.CounterVec
// 分布式协调指标
RemoteAgentCalls *prometheus.CounterVec
RemoteAgentDuration *prometheus.HistogramVec
RemoteAgentErrors *prometheus.CounterVec
// 服务实例指标
ServiceInstances *prometheus.GaugeVec
HealthyInstances *prometheus.GaugeVec
// 并发执行指标
ConcurrentExecutions prometheus.Gauge
}
Metrics Agent 监控指标
type TelemetryConfig ¶
type TelemetryConfig struct {
ServiceName string
ServiceVersion string
Environment string
// Trace
TraceEnabled bool
TraceExporter string // "otlp", "stdout", "noop"
TraceEndpoint string // OTLP endpoint
TraceSampleRate float64 // 0.0 to 1.0
// Metrics
MetricsEnabled bool
MetricsExporter string // "prometheus", "otlp", "noop"
MetricsEndpoint string
MetricsInterval time.Duration
// Logs (optional)
LogsEnabled bool
LogsExporter string
LogsEndpoint string
// Resource attributes
ResourceAttributes map[string]string
}
TelemetryConfig 配置
func DefaultTelemetryConfig ¶
func DefaultTelemetryConfig() *TelemetryConfig
DefaultTelemetryConfig 返回默认配置
type TelemetryProvider ¶
type TelemetryProvider struct {
// contains filtered or unexported fields
}
TelemetryProvider OpenTelemetry 提供者
func NewTelemetryProvider ¶
func NewTelemetryProvider(config *TelemetryConfig) (*TelemetryProvider, error)
NewTelemetryProvider 创建提供者
func (*TelemetryProvider) ForceFlush ¶
func (p *TelemetryProvider) ForceFlush(ctx context.Context) error
ForceFlush 强制刷新
func (*TelemetryProvider) GetMeter ¶
func (p *TelemetryProvider) GetMeter(name string) metric.Meter
GetMeter 获取 Meter