Documentation ¶
Overview ¶
Package tracer provides an interface for distributed tracing
Package tracer provides an interface for distributed tracing
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultTracer is the global default tracer DefaultTracer Tracer = NewTracer() //nolint:revive // TraceIDKey is the key used for the trace id in the log call TraceIDKey = "trace-id" // SpanIDKey is the key used for the span id in the log call SpanIDKey = "span-id" // DefaultSkipEndpoints is the slice of endpoint that must not be traced DefaultSkipEndpoints = []string{ "MeterService.Metrics", "HealthService.Live", "HealthService.Ready", "HealthService.Version", } )
Functions ¶
func NewContext ¶
NewContext saves the tracer in the context
Types ¶
type EventOption ¶
type EventOption func(o *EventOptions)
EventOption func signature
func WithEventLabels ¶ added in v3.10.26
func WithEventLabels(kv ...interface{}) EventOption
type EventOptions ¶
type EventOptions struct {
Labels []interface{}
}
EventOptions contains event options
func NewEventOptions ¶ added in v3.10.28
func NewEventOptions(opts ...EventOption) EventOptions
NewEventOptions returns default EventOptions
type Options ¶
type Options struct { // Context used to store custome tracer options Context context.Context // Logger used for logging Logger logger.Logger // Name of the tracer Name string }
Options struct
type Span ¶
type Span interface { // Tracer return underlining tracer Tracer() Tracer // Finish complete and send span Finish(opts ...SpanOption) // Context return context with span Context() context.Context // SetName set the span name SetName(name string) // SetStatus set the span status code and msg SetStatus(status SpanStatus, msg string) // Status returns span status and msg Status() (SpanStatus, string) // AddLabels append labels to span AddLabels(kv ...interface{}) // AddEvent append event to span AddEvent(name string, opts ...EventOption) // AddEvent append event to span AddLogs(kv ...interface{}) // Kind returns span kind Kind() SpanKind // TraceID returns trace id TraceID() string // SpanID returns span id SpanID() string }
type SpanKind ¶ added in v3.10.3
type SpanKind int
const ( // SpanKindUnspecified is an unspecified SpanKind and is not a valid // SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal // if it is received. SpanKindUnspecified SpanKind = 0 // SpanKindInternal is a SpanKind for a Span that represents an internal // operation within an application. SpanKindInternal SpanKind = 1 // SpanKindServer is a SpanKind for a Span that represents the operation // of handling a request from a client. SpanKindServer SpanKind = 2 // SpanKindClient is a SpanKind for a Span that represents the operation // of client making a request to a server. SpanKindClient SpanKind = 3 // SpanKindProducer is a SpanKind for a Span that represents the operation // of a producer sending a message to a message broker. Unlike // SpanKindClient and SpanKindServer, there is often no direct // relationship between this kind of Span and a SpanKindConsumer kind. A // SpanKindProducer Span will end once the message is accepted by the // message broker which might not overlap with the processing of that // message. SpanKindProducer SpanKind = 4 // SpanKindConsumer is a SpanKind for a Span that represents the operation // of a consumer receiving a message from a message broker. Like // SpanKindProducer Spans, there is often no direct relationship between // this Span and the Span that produced the message. SpanKindConsumer SpanKind = 5 )
type SpanOption ¶
type SpanOption func(o *SpanOptions)
SpanOption func signature
func WithSpanKind ¶ added in v3.10.3
func WithSpanKind(k SpanKind) SpanOption
func WithSpanLabels ¶ added in v3.10.3
func WithSpanLabels(kv ...interface{}) SpanOption
func WithSpanRecord ¶ added in v3.10.74
func WithSpanRecord(b bool) SpanOption
func WithSpanStatus ¶ added in v3.10.77
func WithSpanStatus(st SpanStatus, msg string) SpanOption
type SpanOptions ¶
type SpanOptions struct { StatusMsg string Labels []interface{} Status SpanStatus Kind SpanKind Record bool }
SpanOptions contains span option
func NewSpanOptions ¶ added in v3.10.3
func NewSpanOptions(opts ...SpanOption) SpanOptions
NewSpanOptions returns default SpanOptions
type SpanStatus ¶ added in v3.10.4
type SpanStatus int
const ( // SpanStatusUnset is the default status code. SpanStatusUnset SpanStatus = 0 // SpanStatusError indicates the operation contains an error. SpanStatusError SpanStatus = 1 // SpanStatusOK indicates operation has been validated by an Application developers // or Operator to have completed successfully, or contain no error. SpanStatusOK SpanStatus = 2 )
func (SpanStatus) String ¶ added in v3.10.4
func (s SpanStatus) String() string
type Tracer ¶
type Tracer interface { // Name return tracer name Name() string // Init tracer with options Init(...Option) error // Start a trace Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) // Extract get span metadata from context // Extract(ctx context.Context) // Flush flushes spans Flush(ctx context.Context) error }
Tracer is an interface for distributed tracing
func FromContext ¶
FromContext returns a tracer from context
Click to show internal directories.
Click to hide internal directories.