context

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: 2 Imported by: 0

Documentation

Overview

Package context mirrors Ruby's OpenTelemetry::Context — the immutable, key/value execution context that carries the current span, baggage and any user values across API boundaries.

It is a thin, Ruby-faithful facade over Go's standard context.Context: a Context wraps a Go context so that the OpenTelemetry Go SDK (go.opentelemetry.io/otel) can be driven underneath while callers use the method names and semantics of the opentelemetry-ruby gem.

Like MRI, a Context is immutable: Set returns a new Context and never mutates the receiver. The package also reproduces Ruby's process-wide "current" context managed through Attach/Detach tokens (OpenTelemetry::Context.current, .attach, .detach and .with_current).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear resets the current-context stack. It exists so tests (and long-lived hosts embedding the runtime) can return to a pristine state.

func Detach

func Detach(tok *Token) bool

Detach mirrors OpenTelemetry::Context.detach(token). It pops back to the context that was current when tok was produced and reports whether the token matched the top of the stack (Ruby logs a warning on mismatch; here the mismatch is reported to the caller and the stack is left untouched).

func With

func With(ctx *Context, fn func(*Context))

With mirrors OpenTelemetry::Context.with_current(context) { ... }: it makes ctx current for the duration of fn and restores the previous current context afterwards, even if fn panics.

Types

type Context

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

Context is the Ruby-faithful OpenTelemetry::Context. It wraps a Go context so values, spans and baggage stored by the backing SDK travel with it.

func Background

func Background() *Context

Background returns the empty root Context (OpenTelemetry::Context::ROOT).

func Current

func Current() *Context

Current mirrors OpenTelemetry::Context.current. It returns the most recently attached Context, or the empty root Context when none is attached.

func FromGo

func FromGo(ctx gocontext.Context) *Context

FromGo adapts a standard Go context into a Ruby-faithful Context. It is the seam through which the backing SDK's context (holding the active span and baggage) is surfaced to callers.

func (*Context) Go

func (c *Context) Go() gocontext.Context

Go returns the underlying Go context, for use with the backing SDK.

func (*Context) Set

func (c *Context) Set(key Key, value any) *Context

Set mirrors OpenTelemetry::Context#set_value: it returns a new Context with key bound to value, leaving the receiver unchanged.

func (*Context) Value

func (c *Context) Value(key Key) any

Value mirrors OpenTelemetry::Context#value: it returns the value bound to key, or nil when the key is absent.

type Key

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

Key identifies a value stored in a Context. Distinct Key values never collide even when they share a name, matching MRI's Context.create_key: identity is by the underlying pointer, not the descriptive name.

func CreateKey

func CreateKey(name string) Key

CreateKey mirrors OpenTelemetry::Context.create_key(name).

func (Key) Name

func (k Key) Name() string

Name returns the descriptive name the Key was created with.

type Token

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

Token is returned by Attach and consumed by Detach to restore the previous current Context (OpenTelemetry::Context.attach's return value).

func Attach

func Attach(ctx *Context) *Token

Attach mirrors OpenTelemetry::Context.attach(context): it makes ctx current and returns a Token that Detach uses to restore the prior current context.

Jump to

Keyboard shortcuts

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