class DatadogFormatter

Constants

BASE_TAGS
KEYS_TO_EMIT

Public Class Methods

new(output) click to toggle source
Calls superclass method
# File lib/rspec/datadog.rb, line 23
def initialize(output)
  # Initialize Dogapi client
  @dog = Dogapi::Client.new(ENV['DATADOG_API_KEY'], ENV['DATADOG_APPLICATION_KEY'])

  super
end

Public Instance Methods

close(_notification=nil) click to toggle source
# File lib/rspec/datadog.rb, line 30
def close(_notification=nil)
  # Set now to a value shared by all events for this test run
  now = Time.now.to_i

  datadog_events = @output_hash[:examples].map do |example|
    tags = hash_to_tags(
      example.slice(*KEYS_TO_EMIT)
    )

    Dogapi::Event.new("#{example[:full_description]}: #{example[:status]}",
      :msg_title => "RSpec example",
      :tags => BASE_TAGS + tags,
      :date_happened => now
    )
  end

  datadog_events.each do |event|
    emit_event(event)
  end
end

Private Instance Methods

emit_event(event) click to toggle source
# File lib/rspec/datadog.rb, line 58
def emit_event(event)
  if ENV['DEBUG']
    puts JSON.pretty_generate(event.to_hash)
  else
    @dog.emit_event(event)
  end
end
hash_to_tags(example_hash) click to toggle source
# File lib/rspec/datadog.rb, line 52
def hash_to_tags(example_hash)
  example_hash.map do |k,v|
    "#{k}:#{v}"
  end
end