tracer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package tracer wraps an OpenTelemetry Tracer with a noop default and an errclass Registry so a single RecordError call can classify, record, and set span status. The package deliberately stays thin — SDKs add their own higher-level helpers (events, attributes) on top of this primitive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Recorder

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

Recorder wraps a trace.Tracer and an errclass.Registry.

func New

func New(provider trace.TracerProvider, scopeName, scopeVersion string, classes *errclass.Registry) *Recorder

New returns a Recorder. A nil provider falls back to the noop TracerProvider, a nil classes registry causes all recorded errors to be labeled Unknown.

func (*Recorder) Start

func (r *Recorder) Start(
	ctx context.Context,
	name string,
	kind trace.SpanKind,
	attrs ...attribute.KeyValue,
) (context.Context, *Span)

Start opens a span. A nil receiver is safe and returns a noop span.

func (*Recorder) Tracer

func (r *Recorder) Tracer() trace.Tracer

Tracer returns the underlying OTel Tracer for code that needs direct access.

type Span

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

Span wraps trace.Span with errclass integration. All methods are safe on nil.

func (*Span) AddEvent

func (s *Span) AddEvent(name string, attrs ...attribute.KeyValue)

AddEvent adds a named event with optional attributes.

func (*Span) End

func (s *Span) End()

End finalizes the span.

func (*Span) MarkError

func (s *Span) MarkError(class errclass.Class)

MarkError flags the span as failed with a pre-classified Class but without a backing error value (e.g., a hook gated the call, no exception to capture).

func (*Span) Raw

func (s *Span) Raw() trace.Span

Raw returns the underlying OTel Span. Prefer the wrapper methods where possible.

func (*Span) RecordError

func (s *Span) RecordError(err error) errclass.Class

RecordError classifies err via the registry, records it on the span, sets the error.type attribute, and marks the span status as error. Returns the classified Class so callers can reuse it for metric labels without double classification.

func (*Span) SetAttributes

func (s *Span) SetAttributes(attrs ...attribute.KeyValue)

SetAttributes adds attributes to the span.

func (*Span) SpanContext

func (s *Span) SpanContext() trace.SpanContext

SpanContext returns the underlying span context (useful for exemplar linking).

Jump to

Keyboard shortcuts

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