Documentation
¶
Index ¶
- Variables
- func AddAttributes(c *gin.Context, attrs ...attribute.KeyValue)
- func Close(ctx context.Context) error
- func GetContext(c *gin.Context) context.Context
- func GetTraceID(c *gin.Context) string
- func GetTracer() trace.Tracer
- func Init(cfg Config) error
- func Middleware(serviceName string) gin.HandlerFunc
- func RecordError(c *gin.Context, err error)
- func RecordErrorToSpan(span trace.Span, err error)
- func SetAttribute(c *gin.Context, key string, value any)
- func StartSpan(c *gin.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func StartSpanFromContext(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- type Config
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = Config{ ServiceName: "xlgo-service", ServiceVersion: "1.0.0", Environment: "development", ExporterType: "otlp-http", Endpoint: "localhost:4318", SampleRatio: 1.0, Enabled: false, Propagator: "w3c", }
DefaultConfig 默认配置
Functions ¶
func AddAttributes ¶
AddAttributes 添加属性到当前 Span
func GetContext ¶
GetContext 从 Gin Context 获取 OpenTelemetry Context
func RecordErrorToSpan ¶
RecordErrorToSpan 记录错误到指定 Span
Types ¶
type Config ¶
type Config struct {
// ServiceName 服务名称
ServiceName string
// ServiceVersion 服务版本
ServiceVersion string
// Environment 运行环境
Environment string
// ExporterType 导出器类型: "otlp-http", "otlp-grpc", "stdout"
ExporterType string
// Endpoint OTLP 导出器地址
Endpoint string
// SampleRatio 采样比例 (0.0-1.0)
SampleRatio float64
// Enabled 是否启用
Enabled bool
// Propagator 传播器类型: "w3c", "b3", "jaeger"
Propagator string
}
Config 链路追踪配置
Click to show internal directories.
Click to hide internal directories.