Class: Datadog::Notifications
- Inherits:
-
Object
- Object
- Datadog::Notifications
- Includes:
- Singleton
- Defined in:
- lib/datadog/notifications.rb,
lib/datadog/notifications/config.rb,
lib/datadog/notifications/plugins.rb,
lib/datadog/notifications/version.rb,
lib/datadog/notifications/reporter.rb
Defined Under Namespace
Modules: Plugins Classes: Config, Reporter
Constant Summary collapse
- VERSION =
'0.7.2'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.configure(&block) ⇒ Object
Configure and install datadog instrumentation.
-
.subscribe(pattern, &block) ⇒ Object
You can subscribe to events exactly as with ActiveSupport::Notifications, but there will be an additional ‘statsd` block parameter available:.
Instance Method Summary collapse
-
#initialize ⇒ Notifications
constructor
A new instance of Notifications.
- #subscribe(pattern) ⇒ Object
Constructor Details
#initialize ⇒ Notifications
Returns a new instance of Notifications.
61 62 63 |
# File 'lib/datadog/notifications.rb', line 61 def initialize @config = Config.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
59 60 61 |
# File 'lib/datadog/notifications.rb', line 59 def config @config end |
Class Method Details
.configure(&block) ⇒ Object
Configure and install datadog instrumentation. Example:
Datadog::Notifications.configure do |c|
c.hostname = "my-host"
c. = ["app:mine"]
c.use Datadog::Notifications::Plugins::Grape, metric_name: "api.request", tags: ["grape:specific"]
end
Settings:
-
hostname
- the hostname used for instrumentation, defaults to system hostname, respectsINSTRUMENTATION_HOSTNAME
env variable -
namespace
- set a namespace to be prepended to every metric name -
tags
- set an array of tags to be added to every metric -
statsd_host
- the statsD host, defaults to “localhost”, respectsSTATSD_HOST
env variable -
statsd_port
- the statsD port, defaults to 8125, respectsSTATSD_PORT
env variable -
reporter
- custom reporter class, defaults to ‘Datadog::Notifications::Reporter`
32 33 34 35 36 37 38 |
# File 'lib/datadog/notifications.rb', line 32 def self.configure(&block) if instance.instance_variable_defined?(:@reporter) warn "#{name} cannot be reconfigured once it has subscribed to notifications, called from: #{caller(2..2).first}" return end block&.call instance.config end |
.subscribe(pattern, &block) ⇒ Object
You can subscribe to events exactly as with ActiveSupport::Notifications, but there will be an additional ‘statsd` block parameter available:
Datadog::Notifications.subscribe('render') do |reporter, event|
reporter # => Reporter instance
event # => ActiveSupport::Notifications::Event object
end
Example:
Datadog::Notifications.subscribe('render') do |reporter, _, start, finish, _, payload|
status = payload[:status]
reporter.seconds('myapp.render', finish-start, tags: ["status:#{status}"])
end
55 56 57 |
# File 'lib/datadog/notifications.rb', line 55 def self.subscribe(pattern, &block) instance.subscribe(pattern, &block) end |
Instance Method Details
#subscribe(pattern) ⇒ Object
65 66 67 68 69 |
# File 'lib/datadog/notifications.rb', line 65 def subscribe(pattern) ActiveSupport::Notifications.subscribe(pattern) do |*args| yield reporter, ActiveSupport::Notifications::Event.new(*args) end end |