observability

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAttributes

func AddAttributes(span trace.Span, attrs ...attribute.KeyValue)

AddAttributes 添加属性到 span

func AddEvent

func AddEvent(span trace.Span, name string, attrs ...attribute.KeyValue)

AddEvent 添加事件到 span

func AgentAttributes

func AgentAttributes(agentName, agentType string) []attribute.KeyValue

AgentAttributes 创建 Agent 属性

func DecrementConcurrentExecutions

func DecrementConcurrentExecutions()

DecrementConcurrentExecutions 减少并发执行数

func ErrorAttributes

func ErrorAttributes(errorType, errorMessage string) []attribute.KeyValue

ErrorAttributes 创建错误属性

func IncrementConcurrentExecutions

func IncrementConcurrentExecutions()

IncrementConcurrentExecutions 增加并发执行数

func LLMAttributes

func LLMAttributes(model, provider string, tokens int) []attribute.KeyValue

LLMAttributes 创建 LLM 属性

func MemoryAttributes

func MemoryAttributes(operation, memoryType string, size int) []attribute.KeyValue

MemoryAttributes 创建内存属性

func RecordAgentError

func RecordAgentError(agentName, service, errorType string)

RecordAgentError 记录 Agent 错误

func RecordAgentExecution

func RecordAgentExecution(agentName, service, status string, duration time.Duration)

RecordAgentExecution 记录 Agent 执行

func RecordError

func RecordError(span trace.Span, err error)

RecordError 记录错误到 span

func RecordRemoteAgentCall

func RecordRemoteAgentCall(service, agentName, status string, duration time.Duration)

RecordRemoteAgentCall 记录远程 Agent 调用

func RecordRemoteAgentError

func RecordRemoteAgentError(service, agentName, errorType string)

RecordRemoteAgentError 记录远程 Agent 错误

func RecordToolCall

func RecordToolCall(toolName, agentName, status string, duration time.Duration)

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

func ToolAttributes(toolName, toolType string) []attribute.KeyValue

ToolAttributes 创建工具属性

func UpdateServiceInstances

func UpdateServiceInstances(service string, total, healthy int)

UpdateServiceInstances 更新服务实例数量

func WrapAgent

func WrapAgent(agent agentcore.Agent, serviceName string, logger core.Logger) agentcore.Agent

WrapAgent 包装 Agent 以添加可观测性

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) AddEvent

func (t *AgentTracer) AddEvent(ctx context.Context, name string, attrs ...attribute.KeyValue)

AddEvent 添加事件

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) SetStatus

func (t *AgentTracer) SetStatus(ctx context.Context, code codes.Code, description string)

SetStatus 设置状态

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

func (*AgentTracer) StartToolSpan

func (t *AgentTracer) StartToolSpan(ctx context.Context, toolName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartToolSpan 启动工具调用 span

func (*AgentTracer) WithSpanContext

func (t *AgentTracer) WithSpanContext(ctx context.Context, spanName string, fn func(context.Context) error, attrs ...attribute.KeyValue) error

WithSpanContext 在新 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

func (t *CrossServiceTracer) TraceHTTPResponse(ctx context.Context, resp *http.Response) error

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 载体

func (*HTTPCarrier) Get

func (c *HTTPCarrier) Get(key string) string

Get 获取值

func (*HTTPCarrier) Keys

func (c *HTTPCarrier) Keys() []string

Keys 获取所有键

func (*HTTPCarrier) Set

func (c *HTTPCarrier) Set(key string, value string)

Set 设置值

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

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

Invoke 执行 Agent 并自动记录可观测性数据

func (*InstrumentedAgent) Name

func (i *InstrumentedAgent) Name() string

Name 返回 Agent 名称

func (*InstrumentedAgent) Pipe

Pipe 连接到另一个 Runnable(委托给内部 agent)

func (*InstrumentedAgent) Stream

Stream 流式执行 Agent 并自动记录可观测性数据

func (*InstrumentedAgent) WithCallbacks

WithCallbacks 添加回调处理器(委托给内部 agent)

func (*InstrumentedAgent) WithConfig

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) Get

func (c *MessageCarrier) Get(key string) string

Get 获取值

func (*MessageCarrier) GetMetadata

func (c *MessageCarrier) GetMetadata() map[string]string

GetMetadata 获取完整元数据

func (*MessageCarrier) Keys

func (c *MessageCarrier) Keys() []string

Keys 获取所有键

func (*MessageCarrier) Set

func (c *MessageCarrier) Set(key string, value string)

Set 设置值

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 监控指标

func GetMetrics

func GetMetrics() *Metrics

GetMetrics 获取指标实例

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

func (*TelemetryProvider) GetTracer

func (p *TelemetryProvider) GetTracer(name string) trace.Tracer

GetTracer 获取 Tracer

func (*TelemetryProvider) Shutdown

func (p *TelemetryProvider) Shutdown(ctx context.Context) error

Shutdown 关闭

Jump to

Keyboard shortcuts

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