tracing

package
v1.33.18 Latest Latest
Warning

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

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

Documentation

Overview

Package tracing provides a minimal, zero-dependency tracing API used by Buffalo to instrument long-running build steps (proto compilation, dep fetch, cache lookups, etc.). It is intentionally compatible with the OpenTelemetry semantic model — Span, attributes, status — so that a future adapter can forward spans to an OTel SDK without touching call sites.

By default tracing is a no-op: the global tracer drops every span. Call SetTracer to install a real implementation (e.g. one bridging to go.opentelemetry.io/otel) when the dependency is acceptable for the build.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetTracer

func SetTracer(t Tracer)

SetTracer installs t as the process-wide tracer. Passing nil resets to no-op.

Types

type MemoryTracer

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

MemoryTracer records spans in memory. Safe for tests; not for production.

func NewMemoryTracer

func NewMemoryTracer() *MemoryTracer

NewMemoryTracer returns a fresh in-memory tracer.

func (*MemoryTracer) Spans

func (m *MemoryTracer) Spans() []*RecordedSpan

Spans returns a snapshot of recorded spans.

func (*MemoryTracer) StartSpan

func (m *MemoryTracer) StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)

StartSpan implements Tracer.

type RecordedSpan

type RecordedSpan struct {
	Name       string
	StartTime  time.Time
	EndTime    time.Time
	Attributes map[string]any
	Errors     []error
	StatusCode StatusCode
	StatusDesc string
	// contains filtered or unexported fields
}

RecordedSpan is a span captured by MemoryTracer.

func (*RecordedSpan) Duration

func (s *RecordedSpan) Duration() time.Duration

Duration returns the wall-clock duration. Zero before End().

func (*RecordedSpan) End

func (s *RecordedSpan) End()

End implements Span.

func (*RecordedSpan) RecordError

func (s *RecordedSpan) RecordError(err error)

RecordError implements Span.

func (*RecordedSpan) SetAttribute

func (s *RecordedSpan) SetAttribute(key string, value any)

SetAttribute implements Span.

func (*RecordedSpan) SetStatus

func (s *RecordedSpan) SetStatus(code StatusCode, desc string)

SetStatus implements Span.

type Span

type Span interface {
	SetAttribute(key string, value any)
	RecordError(err error)
	SetStatus(code StatusCode, description string)
	End()
}

Span represents an in-flight unit of work.

func StartSpan

func StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)

StartSpan is a convenience wrapper around GlobalTracer().StartSpan.

type SpanConfig

type SpanConfig struct {
	Attributes map[string]any
}

SpanConfig is the materialized set of SpanOptions.

type SpanOption

type SpanOption func(*SpanConfig)

SpanOption configures a span at creation time.

func WithAttributes

func WithAttributes(attrs map[string]any) SpanOption

WithAttributes seeds the new span with key/value pairs.

type StatusCode

type StatusCode int

StatusCode mirrors the OpenTelemetry status semantics.

const (
	StatusUnset StatusCode = iota
	StatusOK
	StatusError
)

type Tracer

type Tracer interface {
	StartSpan(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
}

Tracer creates spans. Implementations must be safe for concurrent use.

func GlobalTracer

func GlobalTracer() Tracer

GlobalTracer returns the currently installed tracer.

Jump to

Keyboard shortcuts

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