module Rollbar

The Rollbar module. It stores a Rollbar::Notifier per thread and provides some module methods in order to use the current thread notifier.

Allows a Ruby String to be used to pass native Javascript objects/functions when calling JSON#generate with a Rollbar::JSON::JsOptionsState instance.

Example: JSON.generate(

{ foo: Rollbar::JSON::Value.new('function(){ alert("bar") }') },
Rollbar::JSON::JsOptionsState.new

)

> ‘{“foo”:function(){ alert("bar") }}’

MUST use the Ruby JSON encoder, as in the example. The ActiveSupport encoder, which is installed with Rails, is invoked when calling Hash#to_json and as_json, and will not work.

Constants

PUBLIC_NOTIFIER_METHODS
VERSION

Attributes

plugins[W]
root_notifier[W]

Public Class Methods

clear_notifier!() click to toggle source

Clears the current thread notifier and the root notifier. In the practice this should be used only on the specs

# File lib/rollbar.rb, line 119
def clear_notifier!
  self.notifier = nil
  self.root_notifier = nil
end
configuration() click to toggle source

Returns the configuration for the current notifier. The current notifier is Rollbar.notifier and exists one per thread.

# File lib/rollbar.rb, line 84
def configuration
  notifier.configuration
end
configure(&block) click to toggle source

Configures the root notifier and loads the plugins

# File lib/rollbar.rb, line 65
def configure(&block)
  root_notifier.configure(&block)

  plugins.load!
end
last_report() click to toggle source
# File lib/rollbar.rb, line 96
def last_report
  Thread.current[:_rollbar_last_report]
end
last_report=(report) click to toggle source
# File lib/rollbar.rb, line 100
def last_report=(report)
  Thread.current[:_rollbar_last_report] = report
end
notifier() click to toggle source
# File lib/rollbar.rb, line 37
def notifier
  # Use the global instance @root_notifier so we don't fall
  # in a infinite loop
  Thread.current[:_rollbar_notifier] ||= Notifier.new(@root_notifier)
end
notifier=(notifier) click to toggle source
# File lib/rollbar.rb, line 43
def notifier=(notifier)
  Thread.current[:_rollbar_notifier] = notifier
end
plugins() click to toggle source
# File lib/rollbar.rb, line 92
def plugins
  @plugins ||= Rollbar::Plugins.new
end
preconfigure(&block) click to toggle source
# File lib/rollbar.rb, line 60
def preconfigure(&block)
  root_notifier.preconfigure(&block)
end
reconfigure(&block) click to toggle source

Reconfigures the root notifier

# File lib/rollbar.rb, line 72
def reconfigure(&block)
  root_notifier.reconfigure(&block)
end
report_exception(exception, request_data = nil, person_data = nil, level = 'error') click to toggle source

Backwards compatibility methods

# File lib/rollbar.rb, line 163
def report_exception(exception, request_data = nil, person_data = nil,
                     level = 'error')
  Kernel.warn('[DEPRECATION] Rollbar.report_exception has been deprecated, ' \
    'please use log() or one of the level functions')

  scope = {}
  scope[:request] = request_data if request_data
  scope[:person] = person_data if person_data

  Rollbar.scoped(scope) do
    Rollbar.notifier.log(level, exception, :use_exception_level_filters => true)
  end
end
report_message(message, level = 'info', extra_data = nil) click to toggle source
# File lib/rollbar.rb, line 177
def report_message(message, level = 'info', extra_data = nil)
  Kernel.warn('[DEPRECATION] Rollbar.report_message has been deprecated, ' \
    'please use log() or one of the level functions')

  Rollbar.notifier.log(level, message, extra_data)
end
report_message_with_request(message, level = 'info', request_data = nil, person_data = nil, extra_data = nil) click to toggle source
# File lib/rollbar.rb, line 184
def report_message_with_request(message, level = 'info', request_data = nil,
                                person_data = nil, extra_data = nil)
  Kernel.warn('[DEPRECATION] Rollbar.report_message_with_request has been ' \
    'deprecated, please use log() or one of the level functions')

  scope = {}
  scope[:request] = request_data if request_data
  scope[:person] = person_data if person_data

  Rollbar.scoped(:request => request_data, :person => person_data) do
    Rollbar.notifier.log(level, message, extra_data)
  end
end
reset_notifier!() click to toggle source

Resets the scope for the current thread notifier. The notifier reference is kept so we reuse the notifier. This is a change from version 2.13.0. Before this version this method clears the notifier.

It was used in order to reset the scope and reusing the global configuration Rollbar.configuration. Since now Rollbar.configuration points to the current notifier configuration, we can resue the notifier instance and just reset the scope.

# File lib/rollbar.rb, line 113
def reset_notifier!
  notifier.reset!
end
root_notifier() click to toggle source

It’s the first notifier instantiated in the process. We store it so all the next per-thread notifiers can inherit its configuration The methods Rollbar.configure, Rollbar.reconfigure, Rollbar.preconfigure and Rollbar.unconfigure work on this notifier. Before v2.13.0 these methods worked on the global configuration, so in the practice the behavior is the same, since they work on the root notifier’s configuration

# File lib/rollbar.rb, line 56
def root_notifier
  @root_notifier ||= notifier
end
safely?() click to toggle source
# File lib/rollbar.rb, line 88
def safely?
  configuration.safely?
end
scope!(options = {}) click to toggle source
# File lib/rollbar.rb, line 157
def scope!(options = {})
  notifier.scope!(options)
end
scoped(options = {}, config_overrides = {}) { || ... } click to toggle source

Create a new Notifier instance using the received options and set it as the current thread notifier. The calls to Rollbar inside the received block will use then this new Notifier object.

@example

new_scope = { job_type: 'scheduled' }
new_config = { use_async: false }

Rollbar.scoped(new_scope, new_config) do
  begin
    # do stuff
  rescue => e
    Rollbar.error(e)
  end
end
# File lib/rollbar.rb, line 141
def scoped(options = {}, config_overrides = {})
  old_notifier = notifier
  self.notifier = old_notifier.scope(options, config_overrides)

  result = yield
  result
ensure
  self.notifier = old_notifier
end
unconfigure() click to toggle source

Unconfigures the root notifier

# File lib/rollbar.rb, line 77
def unconfigure
  root_notifier.unconfigure
end
with_config(overrides, &block) click to toggle source

Create a new Notifier instance with a new configuration using the current one but merging the passed options.

# File lib/rollbar.rb, line 153
def with_config(overrides, &block)
  scoped(nil, overrides, &block)
end