Class: Sentry::Transport
- Inherits:
-
Object
show all
- Defined in:
- lib/sentry/transport.rb,
lib/sentry/transport/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary
collapse
- PROTOCOL_VERSION =
'5'
- USER_AGENT =
"sentry-ruby/#{Sentry::VERSION}"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configuration) ⇒ Transport
Returns a new instance of Transport.
11
12
13
14
15
|
# File 'lib/sentry/transport.rb', line 11
def initialize(configuration)
@configuration = configuration
@transport_configuration = configuration.transport
@dsn = configuration.dsn
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
9
10
11
|
# File 'lib/sentry/transport.rb', line 9
def configuration
@configuration
end
|
Instance Method Details
#encode(event_hash) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sentry/transport.rb', line 51
def encode(event_hash)
event_id = event_hash[:event_id] || event_hash['event_id']
event_type = event_hash[:type] || event_hash['type']
envelope = " {\"event_id\":\"\#{event_id}\",\"dsn\":\"\#{configuration.dsn.to_s}\",\"sdk\":\#{Sentry.sdk_meta.to_json},\"sent_at\":\"\#{Sentry.utc_now.iso8601}\"}\n {\"type\":\"\#{event_type}\",\"content_type\":\"application/json\"}\n \#{JSON.generate(event_hash)}\n ENVELOPE\n\n envelope\nend\n"
|
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/sentry/transport.rb', line 39
def
now = Sentry.utc_now.to_i
fields = {
'sentry_version' => PROTOCOL_VERSION,
'sentry_client' => USER_AGENT,
'sentry_timestamp' => now,
'sentry_key' => @dsn.public_key
}
fields['sentry_secret'] = @dsn.secret_key if @dsn.secret_key
'Sentry ' + fields.map { |key, value| "#{key}=#{value}" }.join(', ')
end
|
#send_data(data, options = {}) ⇒ Object
17
18
19
|
# File 'lib/sentry/transport.rb', line 17
def send_data(data, options = {})
raise NotImplementedError
end
|
#send_event(event) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/sentry/transport.rb', line 21
def send_event(event)
unless configuration.sending_allowed?
configuration.logger.debug(LOGGER_PROGNAME) { "Event not sent: #{configuration.error_messages}" }
return
end
encoded_data = prepare_encoded_event(event)
return nil unless encoded_data
send_data(encoded_data)
event
rescue => e
failed_for_exception(e, event)
nil
end
|