struct OpenTelemetry::Context

Overview

An immutable set of typed values carried across execution scopes.

Spawned fibers inherit their creator's context. On Crystal 1.19 and 1.20, an Isolated execution context starts at root. Use #wrap to pass a captured context to an isolated or already-running fiber.

Concurrency: context bindings are immutable. Stored values must support the caller's sharing pattern. Attachment and activation are fiber-local.

Defined in:

api/context.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.current : Context #

[View source]
def self.root : Context #

[View source]

Class Method Detail

def self.attach(context : Context) : Token #

[View source]
def self.create_key(name : String, type : T.class) : Key(T) forall T #

[View source]
def self.detach(token : Token) : Bool #

Restores the previous context if token is the top attachment in this fiber.


[View source]
def self.suppress_instrumentation(& : -> U) : U forall U #

[View source]
def self.with(context : Context, & : -> U) : U forall U #

Runs a block with context current and restores the previous attachment scope.


[View source]
def self.with_value(key : Key(T), value : T, & : -> U) : U forall T, U #

[View source]

Instance Method Detail

def []?(key : Key(T)) : T | Nil forall T #

[View source]
def instrumentation_suppressed? : Bool #

[View source]
def suppress_instrumentation : Context #

[View source]
def with_value(key : Key(T), value : T) : Context forall T #

[View source]
def without(key : Key) : Context #

[View source]
def wrap(&block : -> U) : Proc(U) forall U #

Captures this context for a callback, including callbacks run on another fiber.


[View source]