Documentation
¶
Overview ¶
Package trace gives a caller a structured trace of a multi-step run: Span records one named operation, Tracer issues spans and links them through ctx. A leaf package: no internal imports, no exporter, no sampling policy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Span ¶
type Span struct {
// ID identifies this span within its Tracer; never zero.
ID SpanID
// ParentID is the parent span's ID; the zero SpanID on a root
// span.
ParentID SpanID
// Name is the operation name Start received.
Name string
// Start is the time Tracer.Start created the span.
Start time.Time
// contains filtered or unexported fields
}
Span is one named operation with a start time, an end time, a parent link, and caller-set string attributes. Tracer.Start is the constructor; a caller never builds one directly. Safe for concurrent End and SetAttribute calls on one shared *Span, so one parent span may serve several child goroutines.
func SpanFrom ¶
SpanFrom reads the *Span Tracer.Start injected into ctx. The boolean is false when ctx carries no span, matching flow's LoopStateFrom and FailureFrom shape.
func (*Span) Attributes ¶
Attributes returns a copy of the attribute map, safe to read and mutate without the span's lock. The result is empty and non-nil when no attribute was ever set.
func (*Span) Duration ¶
Duration returns EndTime minus Start. The result is zero before End runs and non-negative after.
func (*Span) End ¶
func (s *Span) End()
End records the current time as the span's end time. A second call is a no-op; only the first call's time sticks.
func (*Span) EndTime ¶
EndTime returns the recorded end time. The result is the zero time.Time before End runs.
func (*Span) SetAttribute ¶
SetAttribute records one key-value pair. A later call with the same key overwrites the earlier value. The backing store allocates on the first call only. Works on a live or ended span.
type SpanID ¶
type SpanID uint64
SpanID identifies one Span within its Tracer. Allocation-free and comparable. The zero value means "no parent".
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer issues sequential SpanID values through Start. Create one with New. Safe for concurrent Start calls; a sync.Mutex guards the counter. Every started span is retained, so Spans can report the whole tree after a run ends.
func (*Tracer) Spans ¶
Spans returns every span this Tracer started, in start order. The slice is a copy; the spans themselves stay shared, so Attributes and EndTime read live values. The result is empty and non-nil before any Start call.
func (*Tracer) Start ¶
Start creates a Span named name, sets its ParentID from the span already in ctx, if any, and returns a ctx carrying the new span alongside the span itself. IDs start at one and never repeat, so the zero SpanID stays reserved for "no parent". This is the exported entry point; a caller never constructs a Span directly.