trace

package
v0.0.0-...-de74807 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package trace mirrors Ruby's OpenTelemetry::Trace API — the tracing surface (tracers, spans, span context, kind, status) exposed by the opentelemetry-api gem.

It is a Ruby-faithful facade over the OpenTelemetry Go tracing model (go.opentelemetry.io/otel/trace): the types here wrap the Go API/SDK spans so callers use opentelemetry-ruby method names (in_span, start_span, set_attribute, add_event, record_exception, status=, finish, context) while the real, battle-tested Go SDK does the recording. The tracing model is not reimplemented.

Index

Constants

SpanKind constants mirror OpenTelemetry::Trace::SpanKind's INTERNAL, SERVER, CLIENT, PRODUCER and CONSUMER.

View Source
const (
	Unset = codes.Unset
	Ok    = codes.Ok
	Error = codes.Error
)

Status codes mirror OpenTelemetry::Trace::Status.unset/ok/error.

Variables

This section is empty.

Functions

func AttributesToMap

func AttributesToMap(kvs []attribute.KeyValue) map[string]any

AttributesToMap converts recorded OpenTelemetry attributes back into a Ruby-style hash of native Go values, mirroring how opentelemetry-ruby exposes a span's attributes.

Types

type Span

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

Span mirrors OpenTelemetry::Trace::Span — the handle used to enrich and finish a span. It wraps the backing Go span (recording or non-recording alike), so the same facade serves both the SDK's real spans and the API's no-op span.

Its mutating methods return the receiver so calls can be chained, echoing how the Ruby API returns self.

func NewSpan

func NewSpan(span trace.Span) Span

NewSpan wraps a Go span. It is the seam through which a Tracer surfaces the span it started.

func (Span) AddEvent

func (s Span) AddEvent(name string, attributes map[string]any) Span

AddEvent mirrors OpenTelemetry::Trace::Span#add_event(name, attributes:).

func (Span) Context

func (s Span) Context() SpanContext

Context mirrors OpenTelemetry::Trace::Span#context.

func (Span) Finish

func (s Span) Finish(end ...time.Time)

Finish mirrors OpenTelemetry::Trace::Span#finish. An explicit end timestamp may be supplied; when omitted the span ends now.

func (Span) OTel

func (s Span) OTel() trace.Span

OTel returns the underlying Go span, for use with the backing SDK.

func (Span) RecordException

func (s Span) RecordException(err error, attributes map[string]any) Span

RecordException mirrors OpenTelemetry::Trace::Span#record_exception(error): it records the error as an exception event, with optional extra attributes.

func (Span) Recording

func (s Span) Recording() bool

Recording mirrors OpenTelemetry::Trace::Span#recording?.

func (Span) SetAttribute

func (s Span) SetAttribute(key string, value any) Span

SetAttribute mirrors OpenTelemetry::Trace::Span#set_attribute(key, value).

func (Span) SetAttributes

func (s Span) SetAttributes(m map[string]any) Span

SetAttributes sets several attributes at once (span.add_attributes in Ruby).

func (Span) SetName

func (s Span) SetName(name string) Span

SetName mirrors OpenTelemetry::Trace::Span#name=.

func (Span) SetStatus

func (s Span) SetStatus(status Status) Span

SetStatus mirrors OpenTelemetry::Trace::Span#status=.

type SpanContext

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

SpanContext mirrors OpenTelemetry::Trace::SpanContext — the immutable, serializable identity of a span (trace_id, span_id, trace_flags, tracestate, remote?).

func NewSpanContext

func NewSpanContext(sc oteltrace.SpanContext) SpanContext

NewSpanContext wraps a Go SpanContext. It is the seam used by propagation to surface an extracted remote context.

func (SpanContext) HexSpanID

func (c SpanContext) HexSpanID() string

HexSpanID returns the lowercase-hex span_id (the W3C wire form).

func (SpanContext) HexTraceID

func (c SpanContext) HexTraceID() string

HexTraceID returns the lowercase-hex trace_id (the W3C wire form).

func (SpanContext) OTel

OTel returns the underlying Go SpanContext, for use with the backing SDK.

func (SpanContext) Remote

func (c SpanContext) Remote() bool

Remote mirrors OpenTelemetry::Trace::SpanContext#remote? — whether the context was extracted from a remote parent.

func (SpanContext) Sampled

func (c SpanContext) Sampled() bool

Sampled reports whether the sampled trace-flag is set.

func (SpanContext) SpanID

func (c SpanContext) SpanID() SpanID

SpanID returns the 8-byte span identifier.

func (SpanContext) TraceFlags

func (c SpanContext) TraceFlags() TraceFlags

TraceFlags returns the W3C trace-flags byte.

func (SpanContext) TraceID

func (c SpanContext) TraceID() TraceID

TraceID returns the 16-byte trace identifier.

func (SpanContext) TraceState

func (c SpanContext) TraceState() string

TraceState returns the W3C tracestate as its header string form.

func (SpanContext) Valid

func (c SpanContext) Valid() bool

Valid mirrors OpenTelemetry::Trace::SpanContext#valid? — a non-zero trace_id and span_id.

type SpanID

type SpanID = oteltrace.SpanID

SpanID is an 8-byte span identifier (OpenTelemetry::Trace's span_id).

type SpanKind

type SpanKind = oteltrace.SpanKind

SpanKind mirrors OpenTelemetry::Trace::SpanKind.

type SpanOption

type SpanOption func(*spanConfig)

SpanOption configures a span being started, mirroring the keyword arguments of OpenTelemetry::Trace::Tracer#in_span (attributes:, kind:).

func WithAttributes

func WithAttributes(m map[string]any) SpanOption

WithAttributes sets the span's initial attributes (attributes:).

func WithKind

func WithKind(kind SpanKind) SpanOption

WithKind sets the span's kind (kind:).

type Status

type Status struct {
	Code        StatusCode
	Description string
}

Status mirrors OpenTelemetry::Trace::Status — a code plus an optional, error-only human-readable description.

func StatusError

func StatusError(description string) Status

StatusError mirrors OpenTelemetry::Trace::Status.error(description).

func StatusOK

func StatusOK() Status

StatusOK mirrors OpenTelemetry::Trace::Status.ok.

func StatusUnset

func StatusUnset() Status

StatusUnset mirrors OpenTelemetry::Trace::Status.unset.

type StatusCode

type StatusCode = codes.Code

StatusCode mirrors the OpenTelemetry::Trace::Status codes.

type TraceFlags

type TraceFlags = oteltrace.TraceFlags

TraceFlags is the W3C trace-flags byte (the sampled bit lives here).

type TraceID

type TraceID = oteltrace.TraceID

TraceID is a 16-byte trace identifier (OpenTelemetry::Trace's trace_id).

type Tracer

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

Tracer mirrors OpenTelemetry::Trace::Tracer — the factory that starts spans. It wraps the backing Go tracer obtained from a TracerProvider.

func NewTracer

func NewTracer(tracer oteltrace.Tracer) *Tracer

NewTracer wraps a Go tracer. It is the seam a TracerProvider uses to surface the tracer it created.

func (*Tracer) InSpan

func (t *Tracer) InSpan(parent *rbcontext.Context, name string, fn func(span Span, ctx *rbcontext.Context), opts ...SpanOption)

InSpan mirrors OpenTelemetry::Trace::Tracer#in_span(name, attributes:, kind:) { |span| ... }. It starts a span, makes it the current context for the duration of fn, and finishes it afterwards — even if fn panics. A panic is recorded on the span as an exception, the status is set to error, and the panic is re-raised, matching how the Ruby block form records and re-raises.

func (*Tracer) StartRootSpan

func (t *Tracer) StartRootSpan(parent *rbcontext.Context, name string, opts ...SpanOption) (*rbcontext.Context, Span)

StartRootSpan mirrors OpenTelemetry::Trace::Tracer#start_root_span: it starts a span at the root of a new trace, ignoring any active parent in the context.

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(parent *rbcontext.Context, name string, opts ...SpanOption) (*rbcontext.Context, Span)

StartSpan mirrors OpenTelemetry::Trace::Tracer#start_span(name, with_parent:, attributes:, kind:). It starts a span as a child of parent and returns the span together with a Context carrying it as the active span. The caller is responsible for finishing the span.

type TracerProvider

type TracerProvider interface {
	// Tracer mirrors OpenTelemetry.tracer_provider.tracer(name, version).
	Tracer(name, version string) *Tracer
}

TracerProvider mirrors OpenTelemetry::Trace::TracerProvider — the factory that vends named, versioned tracers. The SDK provides a configurable implementation; the no-op provider below is the API default returned by OpenTelemetry.tracer_provider before the SDK is configured.

func NoopTracerProvider

func NoopTracerProvider() TracerProvider

NoopTracerProvider returns the default, non-recording TracerProvider.

Jump to

Keyboard shortcuts

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