Class: Raven::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
# File 'lib/raven/client.rb', line 18

def initialize(configuration)
  @configuration = configuration
  @processors = configuration.processors.map { |v| v.new(self) }
  @state = ClientState.new
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



16
17
18
# File 'lib/raven/client.rb', line 16

def configuration
  @configuration
end

Instance Method Details

#send_event(event) ⇒ Object



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
# File 'lib/raven/client.rb', line 24

def send_event(event)
  return false unless configuration.sending_allowed?(event)

  # Convert to hash
  event = event.to_hash

  unless @state.should_try?
    failed_send(nil, event)
    return
  end

  Raven.logger.debug "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

#transportObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/raven/client.rb', line 51

def transport
  @transport ||=
    case configuration.scheme
    when 'http', 'https'
      Transports::HTTP.new(configuration)
    when 'dummy'
      Transports::Dummy.new(configuration)
    else
      fail "Unknown transport scheme '#{configuration.scheme}'"
    end
end