Class: Slimy::Reporters::DatadogReporter

Inherits:
BaseReporter show all
Defined in:
lib/slimy/reporters/datadog.rb

Overview

Reporter for sending data to datadog

this requires a DogstatsD instance to operate

Instance Method Summary collapse

Constructor Details

#initialize(dogstatsd) ⇒ DatadogReporter

Returns a new instance of DatadogReporter.



10
11
12
# File 'lib/slimy/reporters/datadog.rb', line 10

def initialize(dogstatsd)
  @dogstatsd = dogstatsd
end

Instance Method Details

#report(context) ⇒ Object

report the given context to datadog



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slimy/reporters/datadog.rb', line 15

def report(context)
  return unless context.reportable?

  sli_status = (context.success? ? "success" : "failure")
  current_span = Datadog.tracer.active_span
  if current_span.nil?
    Rails.logger.debug("COULD NOT FIND SPAN")
  else
    set_tags_on_span(context, sli_status, current_span)
    @dogstatsd.increment("sli.#{context.type}.#{sli_status}",
                         tags: context.tags)
  end
end

#set_tags_on_span(context, sli_status, current_span) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/slimy/reporters/datadog.rb', line 29

def set_tags_on_span(context, sli_status, current_span)
  current_span.set_tag("sli_status", sli_status)
  current_span.set_tag("sli_deadline", context.deadline)
  context.tags.each_pair do |key, value|
    current_span.set_tag(key, value)
  end
end