tracer

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package tracer provides convenience wrapping functionality for tracing feature using OpenTelemetry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSetDefaultTextMapPropagator

func CheckSetDefaultTextMapPropagator()

CheckSetDefaultTextMapPropagator sets the default TextMapPropagator if it is not set previously.

func CommonLabels

func CommonLabels() []attribute.KeyValue

CommonLabels returns common used attribute labels: net.host.ip, host.name.

func Ctx

func Ctx() context.Context

Ctx create ctx with trace

func GetBaggageMap

func GetBaggageMap(ctx context.Context) []baggage.Member

GetBaggageMap retrieves and returns the baggage values as map.

func GetBaggageVar

func GetBaggageVar(ctx context.Context, key string) string

GetBaggageVar retrieves value and returns a *gvar.Var for specified key from baggage.

func GetDefaultTextMapPropagator

func GetDefaultTextMapPropagator() propagation.TextMapPropagator

GetDefaultTextMapPropagator returns the default propagator for context propagation between peers.

func GetSpanID

func GetSpanID(ctx context.Context) string

GetSpanID retrieves and returns SpanId from context. It returns an empty string is tracing feature is not activated.

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID retrieves and returns TraceId from context. It returns an empty string is tracing feature is not activated.

func GetTraceParent

func GetTraceParent(ctx context.Context) string

func MaxContentLogSize

func MaxContentLogSize() int

MaxContentLogSize returns the max log size for request and response body, especially for HTTP/RPC request.

func SetBaggageMap

func SetBaggageMap(ctx context.Context, data map[string]interface{}) context.Context

SetBaggageMap is a convenient function for adding map key-value pairs to baggage. Note that it uses attribute.Any to set the key-value pair.

func SetBaggageValue

func SetBaggageValue(ctx context.Context, key string, value interface{}) context.Context

SetBaggageValue is a convenient function for adding one key-value pair to baggage. Note that it uses attribute.Any to set the key-value pair.

func SetSpanError

func SetSpanError(ctx context.Context, err error)

SetSpanError record error to tracing system

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) (context.Context, error)

WithTraceID injects custom trace id into context to propagate.

Types

type Baggage

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

Baggage holds the data through all tracing spans.

func NewBaggage

func NewBaggage(ctx context.Context) *Baggage

NewBaggage creates and returns a new Baggage object from given tracing context.

func (*Baggage) Ctx

func (b *Baggage) Ctx() context.Context

Ctx returns the context that Baggage holds.

func (*Baggage) GetMap

func (b *Baggage) GetMap() []baggage.Member

GetMap retrieves and returns the baggage values as map.

func (*Baggage) GetVar

func (b *Baggage) GetVar(key string) string

GetVar retrieves value and returns a string for specified key from baggage.

func (*Baggage) SetMap

func (b *Baggage) SetMap(data map[string]interface{}) context.Context

SetMap is a convenient function for adding map key-value pairs to baggage. Note that it uses attribute.Any to set the key-value pair.

func (*Baggage) SetValue

func (b *Baggage) SetValue(key string, value interface{}) context.Context

SetValue is a convenient function for adding one key-value pair to baggage. Note that it uses attribute.Any to set the key-value pair.

type Carrier

type Carrier map[string]interface{}

Carrier is the storage medium used by a TextMapPropagator.

func NewCarrier

func NewCarrier(data ...map[string]interface{}) Carrier

NewCarrier creates and returns a Carrier.

func (Carrier) Get

func (c Carrier) Get(k string) string

Get returns the value associated with the passed key.

func (Carrier) Keys

func (c Carrier) Keys() []string

Keys lists the keys stored in this carrier.

func (Carrier) MustMarshal

func (c Carrier) MustMarshal() []byte

MustMarshal .returns the JSON encoding of c

func (Carrier) Set

func (c Carrier) Set(k, v string)

Set stores the key-value pair.

func (Carrier) String

func (c Carrier) String() string

String converts and returns current Carrier as string.

func (Carrier) UnmarshalJSON

func (c Carrier) UnmarshalJSON(b []byte) error

UnmarshalJSON implements interface UnmarshalJSON for package json.

type Span

type Span struct {
	trace.Span
}

func NewSpan

func NewSpan(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, *Span)

NewSpan creates a span and a context.Context containing the newly-created span.

If the context.Context provided in `ctx` contains a Span then the newly-created Span will be a child of that span, otherwise it will be a root span. This behavior can be overridden by providing `WithNewRoot()` as a SpanOption, causing the newly-created Span to be a root span even if `ctx` contains a Span.

When creating a Span it is recommended to provide all known span attributes using the `WithAttributes()` SpanOption as samplers will only have access to the attributes provided when a Span is created.

Any Span that is created MUST also be ended. This is the responsibility of the user. Implementations of this API may leak memory or other resources if Spans are not ended.

type Tracer

type Tracer struct {
	trace.Tracer
}

Tracer warps tracer.Tracer for compatibility and extension.

func NewTracer

func NewTracer(name ...string) *Tracer

NewTracer creates a named tracer that implements Tracer interface. If the name is an empty string then provider uses default name.

This is short for GetTracerProvider().Tracer(name, opts...)

Directories

Path Synopsis
Package plugins
Package plugins
Package provider
Package provider
Package util
Package util

Jump to

Keyboard shortcuts

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