trace

package
v0.53.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 2 modules, 1 package

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 trace holds the traces signal's ingest model: the []byte-based, OTLP-shaped, zero-alloc batch accepted at the storage boundary (in place of OTel-Go ptrace.Traces), and its projection into the columnar span model the record engine ingests.

A span is a record (mirroring signal/log): its stream identity is the producing Resource+Scope, and its per-record fields (name, kind, status, duration, trace/span ids, attributes, events, links) are columns the query filters by condition. Two trace-specific additions ride along as columns: the raw trace_id (with an equality bloom, so trace-by-id is a bloom-pruned equality fetch) and ingest-computed nested-set ids (so an embedder's TraceQL does ancestor/descendant as range comparisons). Events and links are serialized into byte columns.

Index

Constants

View Source
const (
	ColDuration     = "duration"
	ColKind         = "kind"
	ColStatusCode   = "status_code"
	ColParentID     = "parent_id"        // nested-set parent id (the parent's left), 0 for a root
	ColNestedLeft   = "nested_set_left"  // preorder enter index
	ColNestedRight  = "nested_set_right" // preorder exit index (descendant iff a.left<b.left && b.right<a.right)
	ColTraceID      = "trace_id"
	ColSpanID       = "span_id"
	ColParentSpanID = "parent_span_id"
	ColName         = "name"
	ColStatusMsg    = "status_message"
	ColAttrs        = "attrs"
	ColEvents       = "events"
	ColLinks        = "links"
)

Column names of the traces schema (per-record span columns; the span start time is the implicit primary timestamp / sort key, and the stream id is the Resource+Scope hash).

Variables

Schema is the traces vertical's record-engine column schema. trace_id carries an equality bloom (trace-by-id pruning); name carries a full-text bloom; attrs the attribute bloom.

Functions

func Project added in v0.2.0

func Project(td Traces, emit func(*recordengine.Batch)) (accepted int)

Project iterates a Traces batch and calls emit once per stream (each Resource+Scope group) with a recordengine.Batch of that stream's spans in the traces Schema's column order. It returns how many spans were emitted.

Before projecting, it computes nested-set ids per trace **within this batch**: spans are grouped by trace_id (across resources/scopes — a trace spans services), each trace's parent→child tree is built from parent_span_id, and a DFS assigns left/right/parent ids. A span whose parent is absent from the batch is treated as a root; cross-batch parents therefore get independent numbering (the raw parent_span_id column is always present for the embedder to reconcile). Events and links are serialized into their byte columns.

func PutTraces added in v0.2.0

func PutTraces(t *Traces)

PutTraces resets t and returns it to the pool. Do not use t afterward.

Types

type Event added in v0.2.0

type Event struct {
	Attributes signal.Attributes
	Time       int64
	Name       []byte
	Dropped    uint32
}

Event is a span event (a timestamped, named, attributed point within a span).

func DecodeEvents added in v0.2.0

func DecodeEvents(data []byte) ([]Event, error)

DecodeEvents parses [encodeEvents] output. Bounds-checked; byte fields alias data.

type Link struct {
	Attributes signal.Attributes
	TraceID    []byte
	SpanID     []byte
	TraceState []byte
	Dropped    uint32
}

Link is a span link to another span (possibly in another trace).

func DecodeLinks(data []byte) ([]Link, error)

DecodeLinks parses [encodeLinks] output. Bounds-checked; byte fields alias data.

type ResourceSpans added in v0.2.0

type ResourceSpans struct {
	Resource signal.Resource
	Scopes   []ScopeSpans
}

ResourceSpans groups the spans emitted under one signal.Resource.

func (*ResourceSpans) AddScope added in v0.2.0

func (rs *ResourceSpans) AddScope() *ScopeSpans

AddScope appends a fresh ScopeSpans under the resource.

type ScopeSpans added in v0.2.0

type ScopeSpans struct {
	Scope signal.Scope
	Spans []Span
}

ScopeSpans groups the spans emitted under one signal.Scope. A (Resource, Scope) pair is one span **stream**.

func (*ScopeSpans) AddSpan added in v0.2.0

func (ss *ScopeSpans) AddSpan() *Span

AddSpan appends a fresh, fully-zeroed Span under the scope.

type Span added in v0.2.0

type Span struct {
	Attributes    signal.Attributes
	TraceID       []byte
	SpanID        []byte
	ParentSpanID  []byte
	Name          []byte
	StatusMessage []byte
	TraceState    []byte
	Start         int64
	End           int64
	Kind          int32
	StatusCode    int32
	Flags         uint32
	Dropped       uint32
	Events        []Event
	Links         []Link
}

Span is a single OTLP span. Start/End are unix nanos (Start is the record's primary timestamp; End-Start is the stored duration). TraceID is 16 bytes, SpanID/ParentSpanID are 8 (or nil).

func (*Span) AddEvent added in v0.2.0

func (sp *Span) AddEvent() *Event

AddEvent appends a zeroed Event to the span.

func (sp *Span) AddLink() *Link

AddLink appends a zeroed Link to the span.

type Traces

type Traces struct {
	Resources []ResourceSpans
}

Traces is the internal traces ingest batch — the OTLP Resource→Scope→Span hierarchy with all identity as []byte. Resettable and pool-friendly (see GetTraces/PutTraces); build it with the Add* helpers, which reuse retained capacity.

func GetTraces added in v0.2.0

func GetTraces() *Traces

GetTraces returns a reset Traces from a shared pool; pair with PutTraces.

func (*Traces) AddResource added in v0.2.0

func (t *Traces) AddResource() *ResourceSpans

AddResource appends a fresh ResourceSpans and returns a pointer to it (Resource zeroed, Scopes emptied with capacity retained).

func (*Traces) Reset added in v0.2.0

func (t *Traces) Reset()

Reset clears the batch for reuse, retaining backing arrays.

Jump to

Keyboard shortcuts

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