Class: Stoplight::Sentry::Notifier

Inherits:
Notifier::Base
  • Object
show all
Defined in:
lib/stoplight/sentry/notifier.rb

Overview

Usage:

notifier = Stoplight::Sentry::Notifier.new(Sentry)
Stoplight::Light.default_notifiers += [notifier]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sentry, formatter = nil, **options) ⇒ Notifier

Returns a new instance of Notifier.

Parameters:

  • sentry (::Sentry)
  • formatter (Proc, nil) (defaults to: nil)

    (Stoplight::Default::FORMATTER)

  • options (Hash)

    custom options for the Sentry#capture_message method



26
27
28
29
30
# File 'lib/stoplight/sentry/notifier.rb', line 26

def initialize(sentry, formatter = nil, **options)
  @sentry = sentry
  @formatter = formatter || Stoplight::Default::FORMATTER
  @options = options
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



17
18
19
# File 'lib/stoplight/sentry/notifier.rb', line 17

def formatter
  @formatter
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/stoplight/sentry/notifier.rb', line 21

def options
  @options
end

#sentryObject

Returns the value of attribute sentry.



13
14
15
# File 'lib/stoplight/sentry/notifier.rb', line 13

def sentry
  @sentry
end

Instance Method Details

#notify(light, from_color, to_color, error) ⇒ String

Parameters:

  • light (Stoplight::Light)
  • from_color (String)
  • to_color (String)
  • error
    ]StandardError

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/stoplight/sentry/notifier.rb', line 37

def notify(light, from_color, to_color, error)
  formatter.(light, from_color, to_color, error).tap do |message|
    options.merge(backtrace: error&.backtrace).then do |sentry_options|
      sentry.capture_message(message, **sentry_options)
    end
  end
end