Class: Datadog::Notifications::Plugins::Grape

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/notifications/plugins/grape.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#tags

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Grape

Options:

*:metric_name - the metric name, defaults to “grape.request” *:exception_handler - a custom exception handler proc which accepts an exception object and returns a status *:tags - additional tags



15
16
17
18
19
20
21
22
23
# File 'lib/datadog/notifications/plugins/grape.rb', line 15

def initialize(opts={})
  super
  @metric_name = opts[:metric_name] || "grape.request"
  @exception_handler = opts[:exception_handler] || ->(e) { self.class.exception_status(e) }

  Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
    record reporter, event
  end
end

Instance Attribute Details

#exception_handlerObject (readonly)

Returns the value of attribute exception_handler.



8
9
10
# File 'lib/datadog/notifications/plugins/grape.rb', line 8

def exception_handler
  @exception_handler
end

#metric_nameObject (readonly)

Returns the value of attribute metric_name.



8
9
10
# File 'lib/datadog/notifications/plugins/grape.rb', line 8

def metric_name
  @metric_name
end

Class Method Details

.exception_status(err) ⇒ Object



4
5
6
# File 'lib/datadog/notifications/plugins/grape.rb', line 4

def self.exception_status(err)
  err.respond_to?(:status) ? err.status : 500
end