module RackExtension
Constants
- CURRENT_SPAN_KEY
Public Instance Methods
context_with_span(span, parent_context: OpenTelemetry::Context.current)
click to toggle source
Returns a context containing the span, derived from the optional parent context, or the current context if one was not provided.
@param [optional Context] context The context to use as the parent for
the returned context
# File lib/instrumentation/epsagon_rails_middleware.rb, line 290 def context_with_span(span, parent_context: OpenTelemetry::Context.current) parent_context.set_value(CURRENT_SPAN_KEY, span) end
current_span(context = nil)
click to toggle source
Returns the current span from the current or provided context
@param [optional Context] context The context to lookup the current
{Span} from. Defaults to Context.current
# File lib/instrumentation/epsagon_rails_middleware.rb, line 280 def current_span(context = nil) context ||= OpenTelemetry::Context.current context.value(CURRENT_SPAN_KEY) || OpenTelemetry::Trace::Span::INVALID end
with_span(span) { |s, c| ... }
click to toggle source
Activates/deactivates the Span within the current Context, which makes the “current span” available implicitly.
On exit, the Span that was active before calling this method will be reactivated.
@param [Span] span the span to activate @yield [span, context] yields span and a context containing the span to the block.
# File lib/instrumentation/epsagon_rails_middleware.rb, line 301 def with_span(span) OpenTelemetry::Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c } end