Class: OmniEvent::NewRelicJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/omni_event/new_relic_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(log_attributes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/omni_event/new_relic_job.rb', line 5

def perform(log_attributes)
  config = OmniEvent.configuration

  return unless config.new_relic_enabled
  return unless config.new_relic_api_key.present?
  return unless config..present?

  payload = build_payload(log_attributes)

  response = HTTParty.post(
    "https://insights-collector.newrelic.com/v1/accounts/#{config.}/events",
    headers: {
      "Content-Type" => "application/json",
      "X-Insert-Key"  => config.new_relic_api_key
    },
    body: payload.to_json
  )

  unless response.success?
    Rails.logger.warn "[OmniEvent] NewRelicJob: unexpected response #{response.code}"
  end
rescue => e
  Rails.logger.error "[OmniEvent] NewRelicJob failed: #{e.message}"
end