Class: Sentry::Transport

Inherits:
Object show all
Defined in:
lib/sentry/transport.rb,
lib/sentry/transport/configuration.rb

Direct Known Subclasses

BenchmarkTransport, DummyTransport, HTTPTransport

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

#configurationObject

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



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

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"

#generate_auth_headerObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sentry/transport.rb', line 36

def generate_auth_header
  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

Raises:

  • (NotImplementedError)


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
# 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
end