export

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func New(sink func(Batch), limits ...telemetry.Limits) telemetry.Context

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 added in v0.2.0

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 added in v0.2.0

func SampleRatio(ratio float64) func() bool

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 added in v0.2.0

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

Exporter streams settled spans to a sink without blocking the recorded work.

func NewExporter added in v0.2.0

func NewExporter(options Options) *Exporter

NewExporter starts the exporter goroutine; Close stops it.

func (*Exporter) Close added in v0.2.0

func (e *Exporter) Close(ctx context.Context) error

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 added in v0.2.0

func (e *Exporter) Context() telemetry.Context

Context is the telemetry parent hosts pass to recorded work. Each root span gets its own bounded recorder and trace id.

func (*Exporter) Flush added in v0.2.0

func (e *Exporter) Flush(ctx context.Context) error

Flush delivers every record queued before the call.

func (*Exporter) Stats added in v0.2.0

func (e *Exporter) Stats() Stats

Stats is a snapshot of the exporter's counters.

type Options added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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.

Jump to

Keyboard shortcuts

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