tracex

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const KeySpan = "opentracing_span"

Variables

This section is empty.

Functions

func InjectHttp

func InjectHttp(req *http.Request, span Interface) error

InjectHttp 将span以header的形式注入到http.Request里 这样子在http的接收方就可以解析头部的信息 ExtractHttp

func OpentracingGin

func OpentracingGin() gin.HandlerFunc

OpentracingGin 将在此中间件内生成的span赋值给ctx向下传递, 下层通过tracex.ValueSpan(ctx) 获取span无需再次进行Finish

func OpentracingGrpcClient

func OpentracingGrpcClient() grpc.UnaryClientInterceptor

OpentracingGrpcClient 客户端解码span数据并组装成可以再GRPC中解析的数据

func OpentracingGrpcServer

func OpentracingGrpcServer() grpc.UnaryServerInterceptor

OpentracingGrpcServer 将在此中间件内生成的span赋值给ctx向下传递, 下层通过tracex.ValueSpan(ctx) 获取span无需再次进行Finish

Types

type Config

type Config struct {
	Addr        string `yaml:"addr"`
	ServiceName string `yaml:"service_name"`
	Rate        int    `yaml:"rate"` //0-100
}

type Interface

type Interface interface {
	Info(alternatingKeyValues ...interface{})
	Error(err error)
	Context() opentracing.SpanContext
	Finish()
	IsRegister() bool
	ChildSpan(operationName string) Interface
	ChildContext(ctx context.Context) context.Context
	ChildContextWithSpan(ctx context.Context, operationName string) context.Context
	Opentracer
}

func ExtractHttp

func ExtractHttp(req *http.Request) (Interface, error)

ExtractHttp 解析HTTP请求头,导出Span 这里会执行StartSpan命令,所以需要进行Finis操作

func ValueSpan

func ValueSpan(ctx context.Context) Interface

ValueSpan 从contex.Context中获取 span grpc控制器需要阅读 OpentracingGrpcServer 说明 gin控制器需要阅读 OpentracingGrpcServer 说明

type Opentracer

type Opentracer interface {
	TraceID() string
}

Opentracer 定义公共接口,支持Zipkin Jaeger等等,目前仅实现 Jeager

type Option

type Option func(t *Tracer)

func WithConfig

func WithConfig(conf Config) Option

type Span

type Span struct {
	opentracing.Span
	// contains filtered or unexported fields
}

func (Span) ChildContext

func (s Span) ChildContext(ctx context.Context) context.Context

func (Span) ChildContextWithSpan

func (s Span) ChildContextWithSpan(ctx context.Context, operationName string) context.Context

func (Span) ChildSpan

func (s Span) ChildSpan(operationName string) Interface

ChildSpan 在该Span延伸出子Span,形成一个完整的链路树

func (Span) Context

func (s Span) Context() opentracing.SpanContext

func (Span) Error

func (s Span) Error(err error)

Error 打印错误日志

func (Span) Finish

func (s Span) Finish()

func (Span) Info

func (s Span) Info(alternatingKeyValues ...interface{})

Info 跟s.LogKV是一样的,这里只是规范了下名字

func (Span) IsRegister

func (s Span) IsRegister() bool

func (Span) TraceID

func (s Span) TraceID() string

type TextMD

type TextMD struct {
	metadata.MD
}

func (TextMD) ForeachKey

func (t TextMD) ForeachKey(handler func(key, val string) error) error

ForeachKey 读取metadata中的span信息

func (TextMD) Set

func (t TextMD) Set(key, val string)

Set 重写TextMapWriter的Set方法,我们需要将carrier中的数据写入到metadata中,这样grpc才会携带。

type Tracer

type Tracer struct {
	opentracing.Tracer
	io.Closer
	// contains filtered or unexported fields
}

func Must

func Must(opts ...Option) *Tracer

Jump to

Keyboard shortcuts

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