Documentation ¶
Index ¶
- Constants
- Variables
- func BeltWithSpan(belt *belt.Belt, span Span) *belt.Belt
- func BeltWithTracer(belt *belt.Belt, tracer Tracer) *belt.Belt
- func CtxWithSpan(ctx context.Context, span Span) context.Context
- func CtxWithTracer(ctx context.Context, tracer Tracer) context.Context
- func IsNoopSpan(span Span) bool
- type Hook
- type Hooks
- type NoopSpan
- func (*NoopSpan) Annotate(time.Time, string)
- func (*NoopSpan) Fields() field.AbstractFields
- func (*NoopSpan) Finish()
- func (*NoopSpan) FinishWithDuration(time.Duration)
- func (*NoopSpan) Flush()
- func (*NoopSpan) ID() any
- func (s *NoopSpan) Name() string
- func (s *NoopSpan) Parent() Span
- func (*NoopSpan) SetField(field.Key, field.Value)
- func (*NoopSpan) SetFields(field.AbstractFields)
- func (s *NoopSpan) SetName(name string)
- func (s *NoopSpan) StartTS() time.Time
- func (*NoopSpan) TraceIDs() belt.TraceIDs
- type Span
- func SpanFromBelt(belt *belt.Belt) Span
- func SpanFromCtx(ctx context.Context) Span
- func StartChildSpanFromBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt)
- func StartChildSpanFromCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context)
- func StartSpanFromBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt)
- func StartSpanFromCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context)
- type SpanOption
- type SpanOptionAddFields
- type SpanOptionResetFields
- type SpanOptionRole
- type SpanOptionStart
- type Spans
- type Tracer
Constants ¶
const ( RoleClient = SpanOptionRole("client") RoleServer = SpanOptionRole("server") )
Variables ¶
var ArtifactIDSpan = artifactIDSpan{}
ArtifactIDSpan is the belt.ArtifactID for a Span.
The idea is that Span-s may have children and for convenience it should be possible to pass-through the parents through a context/Belt. So we use the Artifacts registry of the Belt to store the current Span, which could become a parent.
var Default = func() Tracer {
return noopTracer{}
}
Default is the (overridable) function which returns returns the default tracer.
It is used by FromBelt and FromCtx functions if a Tracer is not set in the Belt.
var ToolID = toolID{}
ToolID is the tool.ID used for Tracer.
Functions ¶
func BeltWithSpan ¶
func BeltWithSpan(belt *belt.Belt, span Span) *belt.Belt
BeltWithSpan returns a Belt derivative with the specified Span.
func BeltWithTracer ¶
func BeltWithTracer(belt *belt.Belt, tracer Tracer) *belt.Belt
BeltWithTracer returns a Belt derivative with the specified Tracer.
func CtxWithSpan ¶
CtxWithSpan returns a context derivative/clone with the specified Span.
func CtxWithTracer ¶
CtxWithTracer returns a context derivative/clone with the specified Tracer.
func IsNoopSpan ¶
IsNoopSpan returns true if the given Span is a NoopSpan.
Types ¶
type Hook ¶
type Hook interface { // ProcessSpan is the main method of a Hook. It is executed before sending // a Span (to some backend). If it returns false then any further processing // and sending of the Span is cancelled. ProcessSpan(Span) bool // Flush just gracefully empties all the queues (if there are any). Flush() }
Hook is executed right before sending a Span (to some backend).
type NoopSpan ¶
NoopSpan is a no-op implementation of a Span. Supposed to be used for sampled out spans.
func NewNoopSpan ¶
NewNoopSpan returns a new instance of a NoopSpan.
func (*NoopSpan) FinishWithDuration ¶
FinishWithDuration implements Span.
func (*NoopSpan) SetFields ¶
func (*NoopSpan) SetFields(field.AbstractFields)
SetFields implements Span.
type Span ¶
type Span interface { // ID is the ID for the Span. It may have different types, depending // on specific implementation of the Tracer. // // Not all tracing systems may support that. ID() any // TraceIDs are the set if unique IDs associated with the current context. // // See the description of belt.TraceIDs. // // Not all tracing systems may support that. TraceIDs() belt.TraceIDs // Name is the name of the Span. Usually it explains what happens within // this span. Name() string // StartTS returns the timestamp of the beginning of the Span. // // Can be zero value if unknown. For example it could // happen due sampling, or it could just be not supported // byt a specific implementation. StartTS() time.Time // Fields is the set of structured data attached to the Span. Fields() field.AbstractFields // Parent is the parent Span. If there is no parent then an untyped nil is returned. Parent() Span // SetName sets the Name (see the description of method Name). SetName(string) // Annotate adds an event with the specified timestamp and description to the Span. // // Not all tracing systems may support that. Annotate(ts time.Time, description string) // SetField sets a structured field in the Span. // // Not all tracing systems may support that. SetField(field.Key, field.Value) // SetField set multiple structured fields at once in the Span. // // Not all tracing systems may support that. SetFields(field.AbstractFields) // Finish closes the Span using time.Now() as the ending timestamp and sends it. Finish() // FinishWithDuration closes the Span using startTS+duration as the ending timestamp and sends it. FinishWithDuration(duration time.Duration) // Flush forces to immediatelly empty all the buffers (send if something was delayed and so on). Flush() }
Span is a single time interval.
func SpanFromBelt ¶
func SpanFromBelt(belt *belt.Belt) Span
SpanFromBelt extracts a Span from a Belt (for example, previously derived using StartChildSpanFromBelt, StartChildSpanFromCtx or BeltWithSpan).
func SpanFromCtx ¶
SpanFromCtx returns the current span, given a context. Returns a NoopSpan if one is not set.
func StartChildSpanFromBelt ¶
func StartChildSpanFromBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt)
StartChildSpanFromBelt returns a child span given an Belt. The parent Span is extracted from the Belt. If one is not set, then a `nil` parent is set in the new Span.
The Span and an Belt which includes this Span are returned.
func StartChildSpanFromCtx ¶
func StartChildSpanFromCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context)
StartChildSpanFromCtx creates a child span, given a context. The parent span is extracted from the Belt of the context. If one is not set, then the function returns a new root Span (a Span without a parent).
func StartSpanFromBelt ¶
func StartSpanFromBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt)
StartSpanFromBelt returns a span (without a parent) given an Belt.
The Span and an Belt which includes this Span are returned.
func StartSpanFromCtx ¶
func StartSpanFromCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context)
StartSpanFromCtx creates a new (root) span, given a context.
type SpanOption ¶
type SpanOption interface {
// contains filtered or unexported methods
}
SpanOption is an option which modifies a Span.
If some option is not supported by a specific implementation of the Tracer, then it is just ignored.
type SpanOptionAddFields ¶
SpanOptionAddFields adds more structured fields to the Span.
Note: some distributing tracers may not support logging this data.
type SpanOptionResetFields ¶
type SpanOptionResetFields struct{}
SpanOptionResetFields resets structured fields within the Span to an empty set.
type SpanOptionRole ¶
type SpanOptionRole string
SpanOptionRole defines who is the issuer of this specific Span, which might be useful in some implementations of distributed tracing.
type SpanOptionStart ¶
SpanOptionStart overrides the starting timestamp of the Span.
type Tracer ¶
type Tracer interface { belt.Tool // Start creates a new Span, given its name, parent and options. Start(name string, parent Span, options ...SpanOption) Span // StartWithBelt creates a new root Span, given Belt, name and options. // // The returned Belt is a derivative of the provided one, with the Span added. StartWithBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt) // StartChildWithBelt creates a new child Span, given Belt, name and options. // The parent is extracted from the Belt. If one is not set in there then it is // an equivalent of StartWithBelt (a nil parent is used). // // The returned Belt is a derivative of the provided one, with the Span added. StartChildWithBelt(belt *belt.Belt, name string, options ...SpanOption) (Span, *belt.Belt) // StartWithCtx creates a new root Span, given Context, name and options. // // The returned Context is a derivative of the provided one, with the Span added. // Some implementations also injects a span structure with a specific key to the context. StartWithCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) // StartChildWithCtx creates a new child Span, given Context, name and options. // The parent is extracted from the Belt from the Context. // If one is not set in there then it is an equivalent of StartWithCtx (a nil parent is used). // // The returned Context is a derivative of the provided one, with the Span added. // Some implementations also injects a span structure with a specific key to the context. StartChildWithCtx(ctx context.Context, name string, options ...SpanOption) (Span, context.Context) // WithPreHooks returns a Tracer which includes/appends pre-hooks from the arguments. // // PreHook is the same as "Hook", but executed on early stages of building a Span // (before heavy computations). // // Special case: to reset hooks use `WithPreHooks()` (without any arguments). WithPreHooks(...Hook) Tracer // WithHooks returns a Tracer which includes/appends hooks from the arguments. // // See also description of "Hook". // // Special case: to reset hooks use `WithHooks()` (without any arguments). WithHooks(...Hook) Tracer }
Tracer is a generic abstract distributed tracing system client.