Class: InfluxDB::Rails::Middleware::RequestSubscriber

Inherits:
Subscriber
  • Object
show all
Defined in:
lib/influxdb/rails/middleware/request_subscriber.rb

Overview

:nodoc:

Constant Summary

Constants included from Logger

Logger::PREFIX

Instance Attribute Summary

Attributes inherited from Subscriber

#configuration

Instance Method Summary collapse

Methods inherited from Subscriber

#initialize

Constructor Details

This class inherits a constructor from InfluxDB::Rails::Middleware::Subscriber

Instance Method Details

#call(_name, start, finish, _id, payload) ⇒ Object

rubocop:disable Metrics/MethodLength


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/influxdb/rails/middleware/request_subscriber.rb', line 7

def call(_name, start, finish, _id, payload) # rubocop:disable Metrics/MethodLength
  return unless enabled?

  #ts = InfluxDB.convert_timestamp(finish.utc, configuration.time_precision)
  ts = InfluxDB.convert_timestamp(start.utc, configuration.time_precision)
  tags = tags(payload)
  x_request_id = "AL_NONE"
  al_request_id = "AL_NONE"
  al_request_guid = "AL_NONE"
  al_source = "AL_NONE"
  al_request_client_id = "AL_NONE"

  x_request_id = payload[:headers][:HTTP_X_REQUEST_ID] if(payload[:headers] && payload[:headers][:HTTP_X_REQUEST_ID])
  al_request_id = payload[:headers][:HTTP_AL_REQUEST_ID] if(payload[:headers] && payload[:headers][:HTTP_AL_REQUEST_ID])
  #al_request_id = Thread.current["al_request_id"] if(Thread.current["al_request_id"])
  al_request_guid = payload[:headers][:HTTP_AL_REQUEST_GUID] if(payload[:headers] && payload[:headers][:HTTP_AL_REQUEST_GUID])
  #al_request_guid = Thread.current["al_request_guid"] if(Thread.current["al_request_guid"])
  al_source = payload[:headers][:HTTP_AL_SOURCE] if(payload[:headers] && payload[:headers][:HTTP_AL_SOURCE])
  al_request_client_id = payload[:headers][:HTTP_AL_REQUEST_CLIENT_ID] if(payload[:headers] && payload[:headers][:HTTP_AL_REQUEST_CLIENT_ID])

  al_source = Thread.current["al_source"]
  al_request_client_id = Thread.current["al_request_client_id"]

  begin
    series(payload, start, finish).each do |series_name, value|
      InfluxDB::Rails.client.write_point \
        series_name,
        values:    { value: value, x_request_id: x_request_id, al_request_id: al_request_id, al_request_guid: al_request_guid, al_request_source_id: al_source, al_request_client_id: al_request_client_id },
        tags:      tags,
        timestamp: ts
    end
  rescue StandardError => e
    log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
  ensure
    InfluxDB::Rails.current.reset
  end
end