observability

package
v0.7.0 Latest Latest
Warning

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

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

README

observability 可观测性系统

本模块是 goagent 框架的可观测性系统,集成 OpenTelemetry 框架,提供分布式追踪、指标监控和日志记录能力。

目录

架构设计

系统架构图
graph TB
    subgraph "应用层"
        Agent[Agent 执行]
        Tool[工具调用]
        LLM[LLM 调用]
    end

    subgraph "可观测性层"
        IA[InstrumentedAgent<br/>自动记录]
        AT[AgentTracer<br/>追踪器]
        AM[AgentMetrics<br/>指标]
    end

    subgraph "OpenTelemetry 层"
        TP[TelemetryProvider]
        Tracer[Tracer]
        Meter[Meter]
    end

    subgraph "导出层"
        OTLP[OTLP gRPC]
        Prometheus[Prometheus]
    end

    Agent --> IA
    Tool --> IA
    LLM --> IA
    IA --> AT
    IA --> AM
    AT --> TP
    AM --> TP
    TP --> Tracer
    TP --> Meter
    Tracer --> OTLP
    Meter --> Prometheus

    style TP fill:#e1f5ff
    style IA fill:#e8f5e9
三维可观测性
graph LR
    subgraph "追踪 Tracing"
        Span[Span 管理]
        Context[上下文传播]
        Distributed[分布式追踪]
    end

    subgraph "指标 Metrics"
        Counter[计数器]
        Histogram[直方图]
        Gauge[仪表盘]
    end

    subgraph "日志 Logging"
        Event[事件记录]
        Error[错误记录]
        Attribute[属性标注]
    end

    style Span fill:#e1f5ff
    style Counter fill:#e8f5e9
    style Event fill:#fff3e0

核心组件

1. TelemetryProvider 遥测提供者

OpenTelemetry 核心配置管理:

type TelemetryProvider struct {
    tracerProvider *sdktrace.TracerProvider
    meterProvider  *sdkmetric.MeterProvider
    logger         *log.Logger
    config         *TelemetryConfig
    resource       *resource.Resource
}

配置选项

字段 默认值 说明
ServiceName "agent-service" 服务名称
ServiceVersion "1.0.0" 服务版本
Environment "development" 部署环境
TraceEnabled true 启用追踪
TraceExporter "otlp" 导出器类型
TraceEndpoint "localhost:4317" OTLP 端点
TraceSampleRate 1.0 采样率
MetricsEnabled true 启用指标
MetricsExporter "prometheus" 指标导出器
MetricsInterval 60s 导出间隔
2. AgentTracer 追踪器

Agent 专用追踪器:

type AgentTracer struct {
    tracer trace.Tracer
}

领域特定 Span

方法 说明
StartAgentSpan(ctx, agentName, attrs...) Agent 执行 span
StartToolSpan(ctx, toolName, attrs...) 工具调用 span
StartLLMSpan(ctx, model, attrs...) LLM 调用 span
StartMemorySpan(ctx, operation, attrs...) 内存操作 span
StartChainSpan(ctx, chainName, attrs...) 链执行 span
3. AgentMetrics 指标收集器

基于 OpenTelemetry 的指标:

type AgentMetrics struct {
    meter             metric.Meter
    requestsTotal     metric.Int64Counter
    errorsTotal       metric.Int64Counter
    toolCallsTotal    metric.Int64Counter
    requestDuration   metric.Float64Histogram
    toolDuration      metric.Float64Histogram
    activeAgents      metric.Int64UpDownCounter
}
4. Prometheus 指标(Metrics 单例)
type Metrics struct {
    // Agent 执行指标
    agentExecutions        *prometheus.CounterVec
    agentExecutionDuration *prometheus.HistogramVec
    agentErrors            *prometheus.CounterVec

    // 工具调用指标
    toolCalls              *prometheus.CounterVec
    toolCallDuration       *prometheus.HistogramVec
    toolErrors             *prometheus.CounterVec

    // 分布式调用指标
    remoteAgentCalls       *prometheus.CounterVec
    remoteAgentDuration    *prometheus.HistogramVec

    // 服务实例指标
    serviceInstances       *prometheus.GaugeVec
    healthyInstances       *prometheus.GaugeVec

    // 并发指标
    concurrentExecutions   prometheus.Gauge
}
5. InstrumentedAgent 可观测 Agent

自动记录指标、日志、追踪的 Agent 包装:

type InstrumentedAgent struct {
    agent       agentcore.Agent
    serviceName string
    logger      core.Logger
}

自动记录内容

  • 并发计数变化
  • 执行时长
  • 成功/失败状态
  • 工具调用详情
  • 推理步骤数
6. DistributedTracer 分布式追踪

跨服务追踪上下文传播:

type DistributedTracer struct {
    tracer     trace.Tracer
    propagator propagation.TextMapPropagator
}

支持的载体

  • HTTPCarrier - HTTP 头传播
  • MessageCarrier - 消息队列传播

追踪功能

基础追踪
// 启动 Agent span
ctx, span := agentTracer.StartAgentSpan(ctx, "recommendation-engine",
    attribute.String("user_id", "123"))
defer span.End()

// 添加事件
agentTracer.AddEvent(ctx, "search_started",
    attribute.String("algorithm", "collaborative_filtering"))

// 设置属性
agentTracer.SetAttributes(ctx,
    attribute.Int("items_returned", 10),
    attribute.Float64("confidence", 0.95))

// 记录错误
if err != nil {
    agentTracer.RecordError(ctx, err)
}
在 Span 中执行
err := agentTracer.WithSpanContext(ctx, "find_recommendations",
    func(ctx context.Context) error {
        return findRecommendations(ctx)
    },
    attribute.String("user_id", "user123"))
分布式追踪
// HTTP 请求追踪
tracer := NewCrossServiceTracer("api-gateway")
ctx, span := tracer.TraceHTTPRequest(ctx, httpRequest)
defer span.End()

resp, _ := http.DefaultClient.Do(req)
tracer.TraceHTTPResponse(ctx, resp)

// 消息队列追踪
ctx, span, carrier := tracer.TraceMessage(ctx, "orders.created", messageBytes)
// carrier.GetMetadata() 包含追踪头

指标功能

Prometheus 指标
// 记录 Agent 执行
start := time.Now()
RecordAgentExecution("search-agent", "search-service", "success", time.Since(start))

// 记录工具调用
RecordToolCall("web-search", "search-agent", "success", duration)

// 更新服务实例
UpdateServiceInstances("payment-service", 5, 5)

// 管理并发
IncrementConcurrentExecutions()
defer DecrementConcurrentExecutions()
OpenTelemetry 指标
metrics, _ := NewAgentMetrics(provider, "my-service")

// 记录请求
metrics.RecordRequest(ctx, 0.25, true,
    attribute.String("agent.name", "analyst"))

// 记录 LLM 调用
metrics.RecordLLMCall(ctx, "gpt-4", "openai", 500, 2.5, true)

// 记录内存操作
metrics.RecordMemoryOperation(ctx, "store", "vector", 1024, 0.05, true)

// 活跃 Agent 计数
metrics.IncrementActiveAgents(ctx, 1)

使用方法

初始化
// 配置
config := &TelemetryConfig{
    ServiceName:    "my-agent-service",
    ServiceVersion: "1.0.0",
    TraceExporter:  "otlp",
    TraceEndpoint:  "localhost:4317",
}

// 创建提供者
provider, err := NewTelemetryProvider(config)
defer provider.Shutdown(context.Background())

// 获取 tracer
agentTracer := NewAgentTracer(provider, "my-agent")

// 获取指标
metrics, err := NewAgentMetrics(provider, "my-agent")
包装 Agent
// 创建业务 Agent
agent := &MySearchAgent{}

// 包装为可观测 Agent
wrappedAgent := NewInstrumentedAgent(agent, "search-service", logger)

// 使用(自动记录所有可观测数据)
output, err := wrappedAgent.Invoke(ctx, input)
属性构造器
// Agent 属性
attrs := AgentAttributes("my-agent", "search")

// 工具属性
attrs := ToolAttributes("calculator", "compute")

// LLM 属性
attrs := LLMAttributes("gpt-4", "openai", 500)

// 内存属性
attrs := MemoryAttributes("store", "vector", 1024)

// 错误属性
attrs := ErrorAttributes("timeout", "request timed out")

API 参考

TelemetryProvider
NewTelemetryProvider(config *TelemetryConfig) (*TelemetryProvider, error)
GetTracer(name string) trace.Tracer
GetMeter(name string) metric.Meter
Shutdown(ctx context.Context) error
ForceFlush(ctx context.Context) error
AgentTracer
NewAgentTracer(provider *TelemetryProvider, name string) *AgentTracer
StartSpan(ctx, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartAgentSpan(ctx, agentName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartToolSpan(ctx, toolName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartLLMSpan(ctx, model string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
AddEvent(ctx, name string, attrs ...attribute.KeyValue)
SetAttributes(ctx, attrs ...attribute.KeyValue)
RecordError(ctx, err error, opts ...trace.EventOption)
WithSpanContext(ctx, spanName string, fn func(context.Context) error, attrs ...attribute.KeyValue) error
Metrics 全局函数
GetMetrics() *Metrics
RecordAgentExecution(agentName, service, status string, duration time.Duration)
RecordAgentError(agentName, service, errorType string)
RecordToolCall(toolName, agentName, status string, duration time.Duration)
RecordToolError(toolName, agentName, errorType string)
RecordRemoteAgentCall(service, agentName, status string, duration time.Duration)
UpdateServiceInstances(service string, total, healthy int)
IncrementConcurrentExecutions()
DecrementConcurrentExecutions()
DistributedTracer
NewDistributedTracer(tracer trace.Tracer) *DistributedTracer
InjectContext(ctx, carrier propagation.TextMapCarrier) error
ExtractContext(ctx, carrier propagation.TextMapCarrier) context.Context
StartRemoteSpan(ctx, name string, carrier propagation.TextMapCarrier) (context.Context, trace.Span)

代码结构

observability/
├── telemetry.go              # OpenTelemetry 提供者
├── tracer.go                 # AgentTracer 实现
├── tracing.go                # 基础追踪工具
├── tracing_distributed.go    # 分布式追踪
├── metrics.go                # Prometheus 指标
├── agent_metrics.go          # OpenTelemetry 指标
├── logging.go                # InstrumentedAgent
└── *_test.go                 # 测试文件

最佳实践

  1. 初始化一次:TelemetryProvider 应在应用启动时创建一次
  2. 及时关闭:应用关闭前调用 provider.Shutdown() 确保数据导出
  3. 使用 WithSpanContext:自动记录错误到 span
  4. 包装 Agent:使用 InstrumentedAgent 获得自动可观测性
  5. 采样配置:生产环境建议 TraceSampleRate: 0.1

扩展阅读

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