Class: Sentry::DebugTransport

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/sentry/transport/debug_transport.rb

Overview

DebugTransport is a transport that logs events to a file for debugging purposes.

It can optionally also send events to Sentry via HTTP transport if a real DSN is provided.

Constant Summary collapse

DEFAULT_LOG_FILE_PATH =
File.join("log", "sentry_debug_events.log")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ DebugTransport

Returns a new instance of DebugTransport.



18
19
20
21
22
23
# File 'lib/sentry/transport/debug_transport.rb', line 18

def initialize(configuration)
  @log_file = initialize_log_file(configuration)
  @backend = initialize_backend(configuration)

  super(@backend)
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



16
17
18
# File 'lib/sentry/transport/debug_transport.rb', line 16

def backend
  @backend
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



16
17
18
# File 'lib/sentry/transport/debug_transport.rb', line 16

def log_file
  @log_file
end

Instance Method Details

#clearObject



50
51
52
53
# File 'lib/sentry/transport/debug_transport.rb', line 50

def clear
  File.write(log_file, "")
  log_debug("DebugTransport: Cleared events from #{log_file}")
end

#log_envelope(envelope) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sentry/transport/debug_transport.rb', line 30

def log_envelope(envelope)
  envelope_json = {
    timestamp: Time.now.utc.iso8601,
    envelope_headers: envelope.headers,
    items: envelope.items.map do |item|
      { headers: item.headers, payload: item.payload }
    end
  }

  File.open(log_file, "a") { |file| file << JSON.dump(envelope_json) << "\n" }
end

#logged_envelopesObject



42
43
44
45
46
47
48
# File 'lib/sentry/transport/debug_transport.rb', line 42

def logged_envelopes
  return [] unless File.exist?(log_file)

  File.readlines(log_file).map do |line|
    JSON.parse(line)
  end
end

#send_event(event) ⇒ Object



25
26
27
28
# File 'lib/sentry/transport/debug_transport.rb', line 25

def send_event(event)
  log_envelope(envelope_from_event(event))
  backend.send_event(event)
end