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


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

#configurationObject

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

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

  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

#transportObject


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

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