# module Raven

Inspired by Rails' and Airbrake's backtrace parsers.

Based on ActionDispatch::RemoteIp. All security-related precautions from that middleware have been removed, because the Event IP just needs to be accurate, and spoofing an IP here only makes data inaccurate, not insecure. Don't re-use this module if you have to trust the IP address.

### Constants

AVAILABLE_INTEGRATIONS
VERSION

  Freezing this constant breaks in 1.9.x

### Public Class Methods

inject() click to toggle source

Injects various integrations. Default behavior: inject all available integrations

    # File lib/raven/base.rb, line 60
    def inject
      inject_only(*Raven::AVAILABLE_INTEGRATIONS)
    end

inject_only(*only_integrations) click to toggle source

    # File lib/raven/base.rb, line 69
    def inject_only(*only_integrations)
      only_integrations = only_integrations.map(&:to_s)
      integrations_to_load = Raven::AVAILABLE_INTEGRATIONS & only_integrations
      not_found_integrations = only_integrations - integrations_to_load
      if not_found_integrations.any?
        logger.warn "Integrations do not exist: #{not_found_integrations.join ', '}"
      end
      integrations_to_load &= Gem.loaded_specs.keys
      # TODO(dcramer): integrations should have some additional checks baked-in
      # or we should break them out into their own repos. Specifically both the
      # rails and delayed_job checks are not always valid (i.e. Rails 2.3) and
      # https://github.com/getsentry/raven-ruby/issues/180
      integrations_to_load.each do |integration|
        load_integration(integration)
      end
    end

inject_without(*exclude_integrations) click to toggle source

    # File lib/raven/base.rb, line 64
    def inject_without(*exclude_integrations)
      include_integrations = Raven::AVAILABLE_INTEGRATIONS - exclude_integrations.map(&:to_s)
      inject_only(*include_integrations)
    end

instance() click to toggle source

    # File lib/raven/base.rb, line 41
    def instance
      @instance ||= Raven::Instance.new
    end

load_integration(integration) click to toggle source

    # File lib/raven/base.rb, line 86
    def load_integration(integration)
      require "raven/integrations/#{integration}"
    rescue Exception => error
      logger.warn "Unable to load raven/integrations/#{integration}: #{error}"
    end

safely_prepend(module_name, opts = {}) click to toggle source

    # File lib/raven/base.rb, line 92
    def safely_prepend(module_name, opts = {})
      return if opts[:to].nil? || opts[:from].nil?
      if opts[:to].respond_to?(:prepend, true)
        opts[:to].send(:prepend, opts[:from].const_get(module_name))
      else
        opts[:to].send(:include, opts[:from].const_get("Old" + module_name))
      end
    end

sys_command(command) click to toggle source

    # File lib/raven/base.rb, line 101
    def sys_command(command)
      result = `#{command} 2>&1` rescue nil
      return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
      result.strip
    end