Sha256: 4e5b2c6eadcd7a63907f44c639129ba493cb26429ef06b35d65cd37553affe91

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require "sentry/transport"

module Sentry
  class Client
    attr_reader :transport, :configuration

    def initialize(configuration)
      @configuration = configuration

      if transport_class = configuration.transport.transport_class
        @transport = transport_class.new(configuration)
      else
        @transport =
          case configuration.dsn&.scheme
          when 'http', 'https'
            HTTPTransport.new(configuration)
          else
            DummyTransport.new(configuration)
          end
      end
    end

    def capture_event(event, scope)
      scope.apply_to_event(event)

      if configuration.async?
        begin
          # We have to convert to a JSON-like hash, because background job
          # processors (esp ActiveJob) may not like weird types in the event hash
          configuration.async.call(event.to_json_compatible)
        rescue => e
          configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
          send_event(event)
        end
      else
        send_event(event)
      end

      event
    end

    def event_from_exception(exception)
      return unless @configuration.exception_class_allowed?(exception)

      Event.new(configuration: configuration).tap do |event|
        event.add_exception_interface(exception)
      end
    end

    def event_from_message(message)
      Event.new(configuration: configuration, message: message)
    end

    def send_event(event, hint = nil)
      return false unless configuration.sending_allowed?(event)

      event = configuration.before_send.call(event, hint) if configuration.before_send
      if event.nil?
        configuration.logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
        return
      end

      transport.send_event(event)

      event
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sentry-ruby-0.1.2 lib/sentry/client.rb