Class: NewRelic::Agent::Connect::RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/connect/request_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(new_relic_service, config, event_harvest_config, environment_report) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



12
13
14
15
16
17
# File 'lib/new_relic/agent/connect/request_builder.rb', line 12

def initialize(new_relic_service, config, event_harvest_config, environment_report)
  @service = new_relic_service
  @config = config
  @event_harvest_config = event_harvest_config
  @environment_report = sanitize_environment_report(environment_report)
end

Instance Method Details

#connect_payloadObject

Initializes the hash of settings that we send to the server. Returns a literal hash containing the options



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/new_relic/agent/connect/request_builder.rb', line 21

def connect_payload
  {
    :pid => $$,
    :host => local_host,
    :display_host => Agent.config[:'process_host.display_name'],
    :app_name => Agent.config[:app_name],
    :language => 'ruby',
    :labels => Agent.config.parsed_labels,
    :agent_version => NewRelic::VERSION::STRING,
    :environment => @environment_report,
    :metadata => ,
    :settings => Agent.config.to_collector_hash,
    :high_security => Agent.config[:high_security],
    :utilization => UtilizationData.new.to_collector_hash,
    :identifier => "ruby:#{local_host}:#{Agent.config[:app_name].sort.join(',')}",
    :event_harvest_config => @event_harvest_config
  }
end

#environment_metadataObject



49
50
51
52
53
# File 'lib/new_relic/agent/connect/request_builder.rb', line 49

def 
  env_copy = {}
  ENV.keys.each { |k| env_copy[k] = ENV[k] if /^NEW_RELIC_METADATA_/.match?(k) }
  env_copy
end

#local_hostObject



55
56
57
# File 'lib/new_relic/agent/connect/request_builder.rb', line 55

def local_host
  NewRelic::Agent::Hostname.get
end

#sanitize_environment_report(environment_report) ⇒ Object

We’ve seen objects in the environment report (Rails.env in particular) that can’t serialize to JSON. Cope with that here and clear out so downstream code doesn’t have to check again.



43
44
45
46
47
# File 'lib/new_relic/agent/connect/request_builder.rb', line 43

def sanitize_environment_report(environment_report)
  return NewRelic::EMPTY_ARRAY unless @service.valid_to_marshal?(environment_report)

  environment_report
end