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
- func AttributesToMap(kvs []attribute.KeyValue) map[string]any
- type Span
- func (s Span) AddEvent(name string, attributes map[string]any) Span
- func (s Span) Context() SpanContext
- func (s Span) Finish(end ...time.Time)
- func (s Span) OTel() trace.Span
- func (s Span) RecordException(err error, attributes map[string]any) Span
- func (s Span) Recording() bool
- func (s Span) SetAttribute(key string, value any) Span
- func (s Span) SetAttributes(m map[string]any) Span
- func (s Span) SetName(name string) Span
- func (s Span) SetStatus(status Status) Span
- type SpanContext
- func (c SpanContext) HexSpanID() string
- func (c SpanContext) HexTraceID() string
- func (c SpanContext) OTel() oteltrace.SpanContext
- func (c SpanContext) Remote() bool
- func (c SpanContext) Sampled() bool
- func (c SpanContext) SpanID() SpanID
- func (c SpanContext) TraceFlags() TraceFlags
- func (c SpanContext) TraceID() TraceID
- func (c SpanContext) TraceState() string
- func (c SpanContext) Valid() bool
- type SpanID
- type SpanKind
- type SpanOption
- type Status
- type StatusCode
- type TraceFlags
- type TraceID
- type Tracer
- func (t *Tracer) InSpan(parent *rbcontext.Context, name string, ...)
- func (t *Tracer) StartRootSpan(parent *rbcontext.Context, name string, opts ...SpanOption) (*rbcontext.Context, Span)
- func (t *Tracer) StartSpan(parent *rbcontext.Context, name string, opts ...SpanOption) (*rbcontext.Context, Span)
- type TracerProvider
Constants ¶
const ( Internal = oteltrace.SpanKindInternal Server = oteltrace.SpanKindServer Client = oteltrace.SpanKindClient Producer = oteltrace.SpanKindProducer Consumer = oteltrace.SpanKindConsumer )
SpanKind constants mirror OpenTelemetry::Trace::SpanKind's INTERNAL, SERVER, CLIENT, PRODUCER and CONSUMER.
Status codes mirror OpenTelemetry::Trace::Status.unset/ok/error.
Variables ¶
This section is empty.
Functions ¶
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 ¶
NewSpan wraps a Go span. It is the seam through which a Tracer surfaces the span it started.
func (Span) Context ¶
func (s Span) Context() SpanContext
Context mirrors OpenTelemetry::Trace::Span#context.
func (Span) Finish ¶
Finish mirrors OpenTelemetry::Trace::Span#finish. An explicit end timestamp may be supplied; when omitted the span ends now.
func (Span) RecordException ¶
RecordException mirrors OpenTelemetry::Trace::Span#record_exception(error): it records the error as an exception event, with optional extra attributes.
func (Span) SetAttribute ¶
SetAttribute mirrors OpenTelemetry::Trace::Span#set_attribute(key, value).
func (Span) SetAttributes ¶
SetAttributes sets several attributes at once (span.add_attributes in Ruby).
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 ¶
func (c SpanContext) OTel() oteltrace.SpanContext
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 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:).
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 ¶
StatusError mirrors OpenTelemetry::Trace::Status.error(description).
func StatusUnset ¶
func StatusUnset() Status
StatusUnset mirrors OpenTelemetry::Trace::Status.unset.
type StatusCode ¶
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 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 ¶
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.