Class: Raven::Client

Inherits:
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'
USER_AGENT =
"raven-ruby/#{Raven::VERSION}"
CONTENT_TYPE =
'application/json'

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, hint = nil) ⇒ 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
50
51
52
53
54
55
56
# File 'lib/raven/client.rb', line 24

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

  event_id = event[:event_id] || event['event_id']
  configuration.logger.info "Sending 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


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/raven/client.rb', line 58

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