Documentation
¶
Overview ¶
Package export delivers telemetry to host-owned sinks. The Pi-compatible recorder owns span lifecycle and parentage; export supplies timing and a passive delivery boundary.
New hands a host one whole tree per root span, synchronously at root end, for in-process consumers that need the complete tree (diagnostics, tests). Exporter is the production path: spans leave as they settle, in batches, on a background goroutine, with head sampling, heartbeats and flush on close.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New records one isolated batch per root callback. Child spans share its recorder, bounded by limits (payload capture stays off unless limits opt in). The host must join child work before the root callback returns. Sink failures never alter the callback's value, error, or panic.
func OTLP ¶
func OTLP(endpoint, service string, headers map[string]string, client *http.Client) func(context.Context, []Record) error
OTLP returns a Sink that posts batches as OTLP/HTTP JSON to endpoint (for example http://collector:4318/v1/traces) with the given headers. Heartbeat records are skipped: an OTLP span is written once, when it ends. Span ids are the recorder's per-root ids, so they are unique within a trace.
func SampleRatio ¶
SampleRatio keeps about ratio of root spans: 0 keeps none, 1 keeps all.
Types ¶
type Batch ¶
type Batch struct {
StartedAt time.Time `json:"started_at"`
Duration time.Duration `json:"duration_ns"`
Spans []telemetry.RecordedSpan `json:"spans"`
SpanTimings []telemetry.SpanTiming `json:"span_timings,omitempty"`
Dropped telemetry.Drops `json:"dropped,omitzero"`
}
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
Exporter streams settled spans to a sink without blocking the recorded work.
func NewExporter ¶
NewExporter starts the exporter goroutine; Close stops it.
func (*Exporter) Close ¶
Close stops recording new roots, delivers what is queued and stops the exporter goroutine. Roots still running keep working unrecorded from here; their later spans are dropped and counted.
func (*Exporter) Context ¶
Context is the telemetry parent hosts pass to recorded work. Each root span gets its own bounded recorder and trace id.
type Options ¶
type Options struct {
// Sink receives each batch on the exporter goroutine. An error or panic
// counts the batch as failed and is reported to OnError.
Sink func(context.Context, []Record) error
OnError func(error)
// BatchSize is the most records per delivery; default 256.
BatchSize int
// Interval is the longest a record waits for a fuller batch; default 2s.
Interval time.Duration
// Queue is how many records may wait for the exporter goroutine; default
// 4,096. Recording never blocks: a record beyond it is dropped and counted.
Queue int
// Sample decides once per root span whether its tree is recorded; nil
// records every root. See SampleRatio.
Sample func() bool
// Heartbeat, when positive, exports a snapshot of every running root this
// often, so a long or hung run is visible before it ends.
Heartbeat time.Duration
// Limits bounds each root's recorder; payload capture is off by default.
Limits telemetry.Limits
}
Options configures an Exporter. Zero fields use the defaults.
type Record ¶
type Record struct {
TraceID string `json:"trace_id"`
Span telemetry.RecordedSpan `json:"span"`
Timing telemetry.SpanTiming `json:"timing"`
Active bool `json:"active,omitempty"`
}
Record is one exported span. A settled span is exported once. A heartbeat is a snapshot of a root span that is still running: Active is set and Timing.Duration is the time elapsed so far.
type Stats ¶
type Stats struct {
Exported int64 // records a sink accepted
Failed int64 // records in batches a sink rejected
Dropped int64 // records refused by a full queue or after Close
Unsampled int64 // root spans the sampler skipped
// Recorder sums the Limits drops of finished roots.
Recorder telemetry.Drops
}
Stats counts an exporter's records and its recorders' drops.