trace

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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

func AddAttributes(c *gin.Context, attrs ...attribute.KeyValue)

AddAttributes 添加属性到当前 Span

func Close

func Close(ctx context.Context) error

Close 关闭链路追踪

func GetContext

func GetContext(c *gin.Context) context.Context

GetContext 从 Gin Context 获取 OpenTelemetry Context

func GetTraceID

func GetTraceID(c *gin.Context) string

GetTraceID 获取当前 TraceID

func GetTracer

func GetTracer() trace.Tracer

GetTracer 获取全局 Tracer

func Init

func Init(cfg Config) error

Init 初始化链路追踪

func Middleware

func Middleware(serviceName string) gin.HandlerFunc

Middleware Gin 中间件

func RecordError

func RecordError(c *gin.Context, err error)

RecordError 记录错误

func RecordErrorToSpan

func RecordErrorToSpan(span trace.Span, err error)

RecordErrorToSpan 记录错误到指定 Span

func SetAttribute

func SetAttribute(c *gin.Context, key string, value any)

SetAttribute 设置单个属性

func StartSpan

func StartSpan(c *gin.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan 创建子 Span

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpanFromContext 从 Context 创建 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 链路追踪配置

Jump to

Keyboard shortcuts

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