Class: Raven::Client
- Inherits:
-
Object
- Object
- Raven::Client
- Defined in:
- lib/raven/client.rb
Overview
Encodes events and sends them to the Sentry server.
Constant Summary collapse
- PROTOCOL_VERSION =
'5'.freeze
- USER_AGENT =
"raven-ruby/#{Raven::VERSION}".freeze
- CONTENT_TYPE =
'application/json'.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
- #send_event(event, hint = nil) ⇒ Object
- #transport ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/raven/client.rb', line 15 def initialize(configuration) @configuration = configuration @processors = configuration.processors.map { |v| v.new(self) } @state = ClientState.new end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/raven/client.rb', line 13 def configuration @configuration end |
Instance Method Details
#send_event(event, hint = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/raven/client.rb', line 21 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 "Discarded event because before_send returned nil" return end # Convert to hash event = event.to_hash unless @state.should_try? failed_send(nil, event) return end configuration.logger.info "Sending event #{event[:event_id]} to Sentry" content_type, encoded_data = encode(event) begin transport.send_event(generate_auth_header, encoded_data, :content_type => content_type) successful_send rescue => e failed_send(e, event) return end event end |
#transport ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/raven/client.rb', line 54 def transport @transport ||= case configuration.scheme when 'http', 'https' Transports::HTTP.new(configuration) when 'stdout' Transports::Stdout.new(configuration) when 'dummy' Transports::Dummy.new(configuration) else fail "Unknown transport scheme '#{configuration.scheme}'" end end |