Help us shape the future of Go! Take the 2026 Go Developer Survey

telemetry

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package telemetry exports runs as OpenTelemetry traces over OTLP/HTTP. The Exporter is an eventlog.Sink: it builds spans from the same events as --json and --log-db, and sends them with a stdlib-only OTLP encoder (protobuf or JSON).

Index

Constants

View Source
const (
	// DefaultEndpoint is the OTLP/HTTP traces URL used when nothing is set.
	DefaultEndpoint = "http://localhost:4318/v1/traces"
	// DefaultTimeout bounds each export and the final flush.
	DefaultTimeout = 10 * time.Second
	// DefaultMaxAttributeBytes caps each content attribute.
	DefaultMaxAttributeBytes = 4096
	// DefaultServiceName is the resource service.name.
	DefaultServiceName = "tinyagent"
)

Variables

This section is empty.

Functions

func ErrorStatus

func ErrorStatus(status string) bool

ErrorStatus reports whether a run status marks the root span as an error: every status except Submitted, Completed and NeedsInput.

func ParseTraceParent

func ParseTraceParent(v string) (trace [16]byte, parent [8]byte, ok bool)

ParseTraceParent parses a W3C traceparent header value.

Types

type Exporter

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

Exporter turns one invocation's events into a trace: an invoke_agent root span with chat, execute_tool, hook and subagent spans under it. It is an eventlog.Sink. Spans are buffered and sent in the background in batches and at Close; export problems are only reported by Close.

func New

func New(o Options) (*Exporter, string)

New starts the root span and the background sender. The returned warning is non-empty when TraceParent was set but malformed; the trace then starts fresh.

func NewAttempts added in v0.9.0

func NewAttempts(o Options, id string, count int) (*Exporter, string)

NewAttempts starts the trace for a parent --attempts run: one root span, "tinyagent attempts", that every attempt's invoke_agent span is parented under through TraceParent.

func (*Exporter) Close

func (e *Exporter) Close() string

Close ends any open spans, sends what is left and waits at most the timeout. It returns one warning describing every export failure, or "".

func (*Exporter) Emit

func (e *Exporter) Emit(kind string, fields map[string]any)

Emit records one run event.

func (*Exporter) FinishAttempts added in v0.9.0

func (e *Exporter) FinishAttempts(winner *int, attemptsRun int, stopReason string, costUSD float64, wallMS int64)

FinishAttempts ends a NewAttempts root span with the group's outcome. The span is an error when no attempt passed.

func (*Exporter) Settings

func (e *Exporter) Settings() Settings

Settings returns the exporter's settings.

func (*Exporter) TraceID

func (e *Exporter) TraceID() string

TraceID returns the trace's ID in hex.

func (*Exporter) TraceParent added in v0.9.0

func (e *Exporter) TraceParent() string

TraceParent returns a W3C traceparent naming the root span, for child processes whose spans belong under it.

type Options

type Options struct {
	Settings Settings
	// Model is the provider/model spec the run starts with.
	Model    string
	Task     string
	ReadOnly bool
	Resumed  bool
	Version  string
	// Redactor masks secrets in exported text; nil masks token shapes only.
	Redactor *eventlog.Redactor
	// TraceParent and TraceState are the inbound W3C trace context, if any.
	TraceParent, TraceState string
	// Client sends the exports; nil means a default client.
	Client *http.Client
}

Options describes one invocation to trace.

type Settings

type Settings struct {
	// Endpoint is the full URL spans are POSTed to.
	Endpoint string
	// Protocol is http/protobuf or http/json.
	Protocol string
	// Headers are sent with every export. Their values are secrets: they
	// are never printed.
	Headers     map[string]string
	Timeout     time.Duration
	ServiceName string
	// Resource holds OTEL_RESOURCE_ATTRIBUTES other than service.name.
	Resource          map[string]string
	Content           bool
	MaxAttributeBytes int
}

Settings is the resolved exporter configuration.

func Resolve

func Resolve(c config.OTel, getenv func(string) string) (Settings, error)

Resolve combines the otel config with the standard OTEL_EXPORTER_OTLP_*, OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES variables read through getenv. Config values win; a per-signal (TRACES) variable wins over the generic one. Errors never contain header values.

func (Settings) HeaderValues

func (s Settings) HeaderValues() []string

HeaderValues returns the header values, for redaction.

func (Settings) Host

func (s Settings) Host() string

Host returns the endpoint's host, the only part of it tinyagent prints.

Jump to

Keyboard shortcuts

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