otelKit

package
v3.0.21 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderBaggage 跨服务相关的请求头
	HeaderBaggage = "Baggage"

	KeyTraceId = "trace-id"
	KeySpanId  = "span-id"
)

Variables

View Source
var (
	NotOtelRequestError = errorKit.New("not otel request")

	NotSetupError = errorKit.New("Haven’t been set up correctly")
)
View Source
var NewAddConfig func(opts []metric.AddOption) metric.AddConfig = metric.NewAddConfig

Functions

func GetRemoteSpanCtx

func GetRemoteSpanCtx(r *http.Request) (remoteSpanCtx context.Context, err error)

GetRemoteSpanCtx

PS: (1) 适用场景: 跨服务 + 接收端 (2) 返回的error != nil的情况下,可以判断是否等于 otelKit.NotOtelRequestError.

func InjectBaggage

func InjectBaggage(r *http.Request, spanCtx context.Context, span trace.Span) (err error)

InjectBaggage 使用 baggage 写入 trace id 和 span id

适用场景: 跨服务 + 发送端

func MustSetUp

func MustSetUp(grpcEndpoint, serviceName string, attributeMap map[string]string, opts ...otlptracegrpc.Option)

func NewGinMiddleware

func NewGinMiddleware() (gin.HandlerFunc, error)

NewGinMiddleware

PS: 需要先setup!!!

func NewGrpcTracerProvider

func NewGrpcTracerProvider(endpoint, serviceName string, attributeMap map[string]string, opts ...otlptracegrpc.Option) (*trace.TracerProvider, error)

NewGrpcTracerProvider

PS: (1) 使用 otlptracegrpc; (2) 此方法第二个返回值为nil的情况下,建议立即调用 otel.SetTracerProvider.

@param endpoint 可以为"",将采用默认值: "localhost:4317" @param serviceName 服务名 @param attributeMap 可以为nil @param opts (1) 额外配置(不要涉及 otlptracegrpc.WithEndpoint,因为在此处配了也没用)

(2) otlptracegrpc.WithInsecure(): 	(a) 配置的话,将使用非安全协议(http...);
									(b) 不配置的话,将使用安全协议(https...).
(3) 一般情况下,建议使用: otlptracegrpc.WithInsecure(), otlptracegrpc.WithDialOption(grpc.WithBlock())

func NewHttpTracerProvider

func NewHttpTracerProvider(endpoint, serviceName string, attributeMap map[string]string, opts ...otlptracehttp.Option) (*trace.TracerProvider, error)

NewHttpTracerProvider Deprecated: Use NewGrpcTracerProvider instead.

PS: (1) 使用 otlptracehttp; (2) 此方法第二个返回值为nil的情况下,建议立即调用 otel.SetTracerProvider.

@param endpoint 可以为"",将采用默认值: "localhost:4318" @param serviceName 服务名 @param attributeMap 可以为nil @param opts 额外配置(不要涉及 otlptracehttp.WithEndpoint,因为在此处配了也没用) @param opts (1) 额外配置(不要涉及 otlptracegrpc.WithEndpoint,因为在此处配了也没用)

(2) otlptracegrpc.WithInsecure(): 	(a) 配置的话,将使用非安全协议(http...);
									(b) 不配置的话,将使用安全协议(https...).
(3) 一般情况下,传个 otlptracegrpc.WithInsecure() 就足够了.

func NewRemoteContext

func NewRemoteContext(traceIdStr, spanIdStr string) (context.Context, error)

NewRemoteContext TODO:

@param traceIdStr 请求头中,"trace-id"对应的值 @param spanIdStr 请求头中,"span-id"对应的值

func SetUp

func SetUp(grpcEndpoint, serviceName string, attributeMap map[string]string, opts ...otlptracegrpc.Option) (err error)

func ShutdownTracerProvider

func ShutdownTracerProvider(tp *trace.TracerProvider, timeout time.Duration)

Types

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

func NewTracer

func NewTracer(tracerName string, opts ...trace.TracerOption) *Tracer

NewTracer

@param tracerName 建议为""

func (*Tracer) NewSpanAndStart

func (tracer *Tracer) NewSpanAndStart(parentSpanCtx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Jump to

Keyboard shortcuts

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