trace

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 15

README

framework-trace

Go framework package for trace.

Installation

go get github.com/go-anyway/framework-trace@v1.0.0

Usage

See documentation for usage examples.

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTracer

func GetTracer() trace.Tracer

GetTracer Tracer 获取追踪器

func Init

func Init(cfg Config) error

Init 初始化 OpenTelemetry 追踪

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown 关闭追踪器

func SpanFromContext

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext 从 context 获取 span

func SpanIDFromContext

func SpanIDFromContext(ctx context.Context) string

SpanIDFromContext 从 context 提取 SpanID

func StartSpan

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan 开始一个新的 span

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

TraceIDFromContext 从 context 提取 TraceID

Types

type Config

type Config struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	OTLEndpoint    string // OTLP endpoint, 例如: http://localhost:4318/v1/traces (HTTP) 或 http://localhost:4317 (gRPC)
	Enabled        bool
	SampleRate     float64 // 采样率 0.0-1.0
}

Config 追踪配置

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认配置

func FromAppConfig

func FromAppConfig(appCfg interface{}) Config

FromAppConfig 从 app.TracingConfig 创建 trace.Config

Jump to

Keyboard shortcuts

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