class Airbrake::Context

Represents a thread-safe Airbrake context object, which carries arbitrary information added via {Airbrake.merge_context} calls.

@example

Airbrake::Context.current.merge!(foo: 'bar')

@api private @since v5.2.1

Public Class Methods

current() click to toggle source

Returns current, thread-local, context. @return [self]

# File lib/airbrake-ruby/context.rb, line 13
def self.current
  Thread.current[:airbrake_context] ||= new
end
new() click to toggle source
# File lib/airbrake-ruby/context.rb, line 17
def initialize
  @mutex = Mutex.new
  @context = {}
end

Public Instance Methods

clear() click to toggle source

@return [Hash] clears (resets) the current context

# File lib/airbrake-ruby/context.rb, line 40
def clear
  @mutex.synchronize do
    @context.clear
  end
end
empty?() click to toggle source

@return [Boolean] checks whether the context has any data

# File lib/airbrake-ruby/context.rb, line 47
def empty?
  @context.empty?
end
merge!(other) click to toggle source

Merges the given context with the current one.

@param [Hash{Object=>Object}] other @return [void]

# File lib/airbrake-ruby/context.rb, line 26
def merge!(other)
  @mutex.synchronize do
    @context.merge!(other)
  end
end
to_h() click to toggle source

@return [Hash] duplicated Hash context

# File lib/airbrake-ruby/context.rb, line 33
def to_h
  @mutex.synchronize do
    @context.dup
  end
end