Sha256: 429b359fa5b95fb3b6ca5aceae95ca7e43372d27abb117b717f94ed5578b36fa

Contents?: true

Size: 1.32 KB

Versions: 68

Compression:

Stored size: 1.32 KB

Contents

require "sentry-ruby"
require "sentry-rails" if defined?(Rails)
require "govuk_app_config/govuk_statsd"
require "govuk_app_config/govuk_error/configuration"
require "govuk_app_config/version"

module GovukError
  class AlreadyInitialised < StandardError
    def initialize(msg = "You can only call GovukError.configure once!")
      super
    end
  end

  def self.notify(exception_or_message, args = {})
    # Allow users to use `parameters` as a key like the Airbrake
    # client, allowing easy upgrades.
    args[:extra] ||= {}
    args[:extra].merge!(parameters: args.delete(:parameters))

    args[:tags] ||= {}
    args[:tags][:govuk_app_config_version] = GovukAppConfig::VERSION

    if exception_or_message.is_a?(String)
      Sentry.capture_message(exception_or_message, **args)
    else
      Sentry.capture_exception(exception_or_message, **args)
    end
  end

  def self.is_configured?
    Sentry.get_current_client != nil
  end

  def self.configure
    raise GovukError::AlreadyInitialised if is_configured?

    if defined?(Sidekiq) && !defined?(Sentry::Sidekiq)
      warn "Warning: GovukError is not configured to track Sidekiq errors, install the sentry-sidekiq gem to track them."
    end

    Sentry.init do |sentry_config|
      config = Configuration.new(sentry_config)
      yield config if block_given?
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
govuk_app_config-9.16.1 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.16.0 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.8 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.7 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.6 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.5 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.4 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.3 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.2 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.1 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.15.0 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.6 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.5 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.4 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.3 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.2 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.1 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.14.0 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.13.1 lib/govuk_app_config/govuk_error.rb
govuk_app_config-9.13.0 lib/govuk_app_config/govuk_error.rb