Documentation
¶
Index ¶
- Constants
- Variables
- func Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
- func ExtractMD(ctx context.Context, metadata metadata.MD) context.Context
- func ExtractSpanFormCtx(ctx context.Context, opts ...trace.TracerOption) (trace.Tracer, context.Context)
- func Inject(ctx context.Context, carrier propagation.TextMapCarrier)
- func InjectMD(ctx context.Context, metadata metadata.MD)
- func NewSpanOutgoingContext(ctx context.Context, span trace.Span) context.Context
- func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue)
- func PeerAddrFromCtx(ctx context.Context) string
- func PeerAttr(addr string) []attribute.KeyValue
- func RegistorTP(ctx context.Context, host string, opts ...TracerOption) error
- func ResolveGrpcInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue)
- func SpanIDFromContext(ctx context.Context) string
- func StatusCodeAttr(c gcodes.Code) attribute.KeyValue
- func TracerFromContext(ctx context.Context) (tracer trace.Tracer)
- type Tracer
- type TracerOption
- func WithExtraResource(kv []attribute.KeyValue) TracerOption
- func WithGlobal(global bool) TracerOption
- func WithName(name string) TracerOption
- func WithOtlpHeaders(headers map[string]string) TracerOption
- func WithOtlpHttpPath(path string) TracerOption
- func WithOtlpHttpSecure(secure bool) TracerOption
- func WithSampler(sampler float64) TracerOption
Constants ¶
const ( // GRPCStatusCodeKey 是用于表示gRPC请求数字状态码的约定, GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code") // RPCNameKey 是传输或接收的消息的名称, RPCNameKey = attribute.Key("name") // RPCMessageTypeKey 是传输或接收的消息的类型, RPCMessageTypeKey = attribute.Key("message.type") // RPCMessageIDKey 是传输或接收的消息的标识符, RPCMessageIDKey = attribute.Key("message.id") // RPCMessageCompressedSizeKey 是传输或接收的消息的压缩大小,以字节为单位, RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size") // RPCMessageUncompressedSizeKey 是传输或接收的消息的未压缩大小,以字节为单位, RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size") )
const KTraceName = "goken"
Variables ¶
var ( // RPCSystemGRPC 是将 gRPC 作为远程系统的语义约定, RPCSystemGRPC = semconv.RPCSystemKey.String("grpc") // RPCNameMessage 是名为message的消息的语义约定, RPCNameMessage = RPCNameKey.String("message") // RPCMessageTypeSent 是发送的RPC消息类型的语义约定, RPCMessageTypeSent = RPCMessageTypeKey.String("SENT") // RPCMessageTypeReceived 是接收的RPC消息类型的语义约定, RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED") )
常见RPC属性的otel自建的语义约定
var ( // MessageSent 表示已发送的消息类型, MessageSent = messageType(RPCMessageTypeSent) // MessageReceived 表示已接收的消息类型, MessageReceived = messageType(RPCMessageTypeReceived) )
var TraceIdKey = http.CanonicalHeaderKey("x-trace-id")
TraceIdKey is the trace id header. https://www.w3.org/TR/trace-context/#trace-id May change it to trace-id afterward.
Functions ¶
func Extract ¶
func Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
注意,Extract不会把span信息以context的形式抽取出,而是把span的spanContext信息抽取到ctx中
func ExtractSpanFormCtx ¶
func ExtractSpanFormCtx(ctx context.Context, opts ...trace.TracerOption) (trace.Tracer, context.Context)
从ctx中获取记录的tracer和spanCtx以便直接生成新span
func Inject ¶
func Inject(ctx context.Context, carrier propagation.TextMapCarrier)
注意,Inject不会把span信息以context的形式注入到ctx中,而是把span的spanContext信息注入到carrier中
func NewSpanOutgoingContext ¶
将ctx中的span信息注入到metadata中
func ParseFullMethod ¶
ParseFullMethod returns the method name and attributes.
func RegistorTP ¶
func RegistorTP(ctx context.Context, host string, opts ...TracerOption) error
注册对应的traceProvider
func ResolveGrpcInfo ¶
SpanInfo 返回
func SpanIDFromContext ¶
func StatusCodeAttr ¶
StatusCodeAttr 返回一个表示给定gRPC状态码的attribute.KeyValue,
Types ¶
type Tracer ¶
type Tracer struct {
Ctx context.Context
// 记录traceProvider的serviceName
ServiceName string
// Sampler 记录基准采样率,派生的span采样率不会低于该百分比,至多百分百采样
Sampler float64
ExtraResources []attribute.KeyValue
// OtlpHeaders是OTLP gRPC或HTTP传输的headers,例如:
// uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'
OtlpHeaders map[string]string
// OtlpHttpPath是OTLP HTTP传输的路径,例如:/v1/traces
OtlpHttpPath string
// OtlpHttpSecure 指定 OTLP HTTP传输是否使用安全的HTTPS协议,
OtlpHttpSecure bool
// Global 表示是否将生成的TraceProvider加入到全局中
Global bool
}
func MustNewTracer ¶
func MustNewTracer(ctx context.Context, opts ...TracerOption) *Tracer
NewTracer 创建一个默认的 Tracer
func (*Tracer) AddResources ¶
func (*Tracer) NewTraceProvider ¶
func (c *Tracer) NewTraceProvider(host string) (*sdktrace.TracerProvider, error)
type TracerOption ¶
type TracerOption func(*Tracer)
func WithExtraResource ¶
func WithExtraResource(kv []attribute.KeyValue) TracerOption
WithGlobal 添加额外的字段信息
func WithGlobal ¶
func WithGlobal(global bool) TracerOption
WithGlobal 设置是否将生成的 TraceProvider 加入到全局中
func WithOtlpHeaders ¶
func WithOtlpHeaders(headers map[string]string) TracerOption
WithOtlpHeaders 设置 OTLP 传输使用的 headers
func WithOtlpHttpPath ¶
func WithOtlpHttpPath(path string) TracerOption
WithOtlpHttpPath 设置 OTLP HTTP 传输的路径
func WithOtlpHttpSecure ¶
func WithOtlpHttpSecure(secure bool) TracerOption
WithOtlpHttpSecure 设置 OTLP HTTP 传输是否使用 HTTPS
func WithSampler ¶
func WithSampler(sampler float64) TracerOption
WithSampler 设置采样率,值为 [0.0, 1.0] 之间