tracing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tracing provides lightweight distributed tracing for the CLI execution path.

Unlike full OTel, this uses a simple span-based model that flows through Cobra command context without external dependencies. Suitable for local debugging and production diagnostics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, trace *Trace) context.Context

NewContext returns a context with the trace attached.

Types

type Span

type Span struct {
	Name     string
	Start    time.Time
	End      time.Time
	Duration time.Duration
	Error    error
	Attrs    map[string]string
	Children []*Span
	// contains filtered or unexported fields
}

Span represents a single operation in a trace.

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, name string) *Span

StartSpanFromContext creates a root span, using the trace from context. If no trace is in context, creates and returns a detached span.

func (*Span) Child

func (s *Span) Child(name string) *Span

Child creates a child span.

func (*Span) Finish

func (s *Span) Finish(err ...error)

Finish marks the span as complete and records duration.

func (*Span) SetAttr

func (s *Span) SetAttr(key, value string)

SetAttr adds a key-value attribute to the span.

type Trace

type Trace struct {
	ID    string
	Spans []*Span
	// contains filtered or unexported fields
}

Trace is the root of a trace, containing one or more root spans.

func FromContext

func FromContext(ctx context.Context) *Trace

FromContext retrieves the trace from a context, or returns nil.

func NewTrace

func NewTrace(id string) *Trace

NewTrace creates a new trace with a unique ID.

func (*Trace) Format

func (t *Trace) Format() string

Format returns a human-readable trace summary.

func (*Trace) StartSpan

func (t *Trace) StartSpan(name string) *Span

StartSpan creates a new root span in the trace.

Jump to

Keyboard shortcuts

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