module Aws::Xray

Constants

TRACE_HEADER
VERSION

Attributes

config[R]

Public Class Methods

current_context() click to toggle source

Return current tracing context set to current thread.

@return [Aws::Xray::Context] @raise [Aws::Xray::NotSetError] when the current context is not yet set.

Call this method after start tracing with `Aws::Xray.trace`.
# File lib/aws/xray.rb, line 67
def current_context
  Context.current
end
disable_trace(id, &block) click to toggle source

Temporary disabling tracing for given id in given block. CAUTION: the disabling will NOT be propagated between threads!!

@param [Symbol] id @return [Object] result of given block

# File lib/aws/xray.rb, line 84
def disable_trace(id, &block)
  if started?
    current_context.disable_trace(id, &block)
  else
    block.call
  end
end
disabled?(id) click to toggle source

Returns whether tracing is disabled with `.disable_trace` for given `id`. @param [Symbol] id @return [Boolean]

# File lib/aws/xray.rb, line 95
def disabled?(id)
  started? && current_context.disabled?(id)
end
overwrite(name:, &block) click to toggle source

Temporary overwrite subsegment with the name in the block. The overwriting will be occured only one time. If current context is not set to current thread, do nothing. CAUTION: the injection will NOT be propagated between threads!!

@param [String] name @return [Object] result of given block

# File lib/aws/xray.rb, line 106
def overwrite(name:, &block)
  if started?
    current_context.overwrite(name: name, &block)
  else
    block.call
  end
end
start_subsegment(name:, remote:, &block) click to toggle source

Start subsegment if current thread has tracing context then send the subsegment to X-Ray daemon. Rescue all exceptions and record the exception to the subsegment. Then re-raise the exception.

@yield [Aws::Xray::Subsegment] null subsegment @return [Object] result of given block

# File lib/aws/xray.rb, line 48
def start_subsegment(name:, remote:, &block)
  if started?
    current_context.start_subsegment(name: name, remote: remote, &block)
  else
    block.call(Subsegment.build_null)
  end
end
started?() click to toggle source

Returns whether tracing context is started or not. @return [Boolean]

# File lib/aws/xray.rb, line 58
def started?
  Context.started?
end
trace(name: nil, trace: Trace.generate) { |seg| ... } click to toggle source

Start new tracing context and segment. If `trace` is given it start tracing context following given `trace`. If `name` is omitted, it uses global application name. Rescue all exceptions and record the exception to the segment. Then re-raise the exception.

@param [String] name a logical name of this tracing context. @return [Object] result of given block

# File lib/aws/xray.rb, line 33
def trace(name: nil, trace: Trace.generate)
  name = name || config.name || raise(MissingNameError)
  Context.with_new_context(name, trace) do
    Context.current.start_segment do |seg|
      yield seg
    end
  end
end
with_given_context(context, &block) click to toggle source

Set tracing context to current thread with given context object.

@param [Aws::Xray::Context] context copied context @return [Object] result of given block

# File lib/aws/xray.rb, line 75
def with_given_context(context, &block)
  Context.with_given_context(context, &block)
end