lib/sapience/appender/datadog.rb in sapience-1.0.5 vs lib/sapience/appender/datadog.rb in sapience-1.0.6
- old
+ new
@@ -9,10 +9,12 @@
# Sapience.add_appender(:datadog, {url: "udp://localhost:2222"})
#
module Sapience
module Appender
class Datadog < Sapience::Subscriber
+ VALIDATION_MESSAGE = "Statsd only supports udp. Example: 'udp://localhost:8125'".freeze
+
# Create Appender
#
# Parameters:
# level: :trace
# url: [String]
@@ -30,20 +32,24 @@
def initialize(options = {}, &block)
fail("Options should be a Hash") unless options.is_a?(Hash)
url = options.delete(:url) || "udp://localhost:8125"
@tags = options.delete(:tags)
@uri = URI.parse(url)
- fail('Statsd only supports udp. Example: "udp://localhost:8125"') if @uri.scheme != "udp"
super(options, &block)
end
def provider
@_provider ||= ::Datadog::Statsd.new(@uri.host, @uri.port, dog_options)
end
+ def valid?
+ @uri.scheme == "udp"
+ end
+
# Send an error notification to sentry
def log(log)
+ return false unless valid?
metric = log.metric
return false unless metric
if log.duration
timing(metric, log.duration, tags: log.tags)
@@ -56,44 +62,53 @@
def timing(metric, duration = 0, options = {})
if block_given?
start = Time.now
yield
+ return false unless valid?
provider.timing(metric, ((Time.now - start) * 1000).floor, options)
else
+ return false unless valid?
provider.timing(metric, duration, options)
end
end
def increment(metric, options = {})
+ return false unless valid?
provider.increment(metric, options)
end
def decrement(metric, options = {})
+ return false unless valid?
provider.decrement(metric, options)
end
def histogram(metric, amount, options = {})
+ return false unless valid?
provider.histogram(metric, amount, options)
end
def gauge(metric, amount, options = {})
+ return false unless valid?
provider.gauge(metric, amount, options)
end
def count(metric, amount, options = {})
+ return false unless valid?
provider.count(metric, amount, options)
end
def time(metric, options = {}, &block)
+ return false unless valid?
provider.time(metric, options, &block)
end
def batch(&block)
provider.batch(&block)
end
def event(title, text, options = {})
+ return false unless valid?
provider.event(title, text, options)
end
def namespace
ns = Sapience.namify(app_name)