Class: Cybertrain::ErrorReporter::SentrySender

Inherits:
Sender
  • Object
show all
Defined in:
cybertrain/error_reporter/sentry.rb

Overview

Sends each event to the Sentry (or GlitchTip) project of Config#sentry_dsn. Installed by requiring this file.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ SentrySender

Returns a new instance of SentrySender.



44
45
46
47
48
49
50
# File 'cybertrain/error_reporter/sentry.rb', line 44

def initialize
  # The DSN last parsed, by its text: parsed again only when the
  # setting changes (a test points it at a receiver). Read and written
  # on the delivery thread only.
  @dsn_text = ""
  @dsn = SentryDsn.new("", "", "", "")
end

Instance Method Details

#deliver_event(event) ⇒ Boolean

Sends one event, unless the sample rate leaves it out; true when Sentry accepted it (a 2xx answer). Never raises: a failure is logged at warn and answers false.

Parameters:

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
80
# File 'cybertrain/error_reporter/sentry.rb', line 72

def deliver_event(event)
  text = Cybertrain.config.sentry_dsn.to_s
  return false if text.empty?

  rate = Cybertrain.config.error_sample_rate.to_f
  return false if rate < 1.0 && !SentrySender.sampled?(rate, SentrySender.sample_draw)

  post_event(text, event)
end

#sender_name ⇒ String

The line this sender comes from (Application#validate_boot asks).

Returns:

  • (String) —

    "sentry"



62
63
64
# File 'cybertrain/error_reporter/sentry.rb', line 62

def sender_name
  "sentry"
end

#sends? ⇒ Boolean

Whether a DSN is set.

Returns:

  • (Boolean)


55
56
57
# File 'cybertrain/error_reporter/sentry.rb', line 55

def sends?
  !Cybertrain.config.sentry_dsn.to_s.empty?
end