Class: ScoutApm::Reporter
- Inherits:
-
Object
- Object
- ScoutApm::Reporter
- Defined in:
- lib/scout_apm/reporter.rb
Constant Summary collapse
- VERIFY_MODE =
OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#instant_key ⇒ Object
readonly
Returns the value of attribute instant_key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #can_report? ⇒ Boolean
- #config ⇒ Object
-
#initialize(context, type, instant_key = nil) ⇒ Reporter
constructor
A new instance of Reporter.
- #logger ⇒ Object
-
#report(payload, headers = {}) ⇒ Object
The fully serialized string payload to be sent.
- #uri(host) ⇒ Object
Constructor Details
#initialize(context, type, instant_key = nil) ⇒ Reporter
Returns a new instance of Reporter.
11 12 13 14 15 |
# File 'lib/scout_apm/reporter.rb', line 11 def initialize(context, type, instant_key=nil) @context = context @type = type @instant_key = instant_key end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/scout_apm/reporter.rb', line 8 def context @context end |
#instant_key ⇒ Object (readonly)
Returns the value of attribute instant_key.
9 10 11 |
# File 'lib/scout_apm/reporter.rb', line 9 def instant_key @instant_key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/scout_apm/reporter.rb', line 7 def type @type end |
Instance Method Details
#can_report? ⇒ Boolean
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/scout_apm/reporter.rb', line 61 def can_report? case type when :deploy_hook %w(host key name).each do |k| if config.value(k).nil? logger.warn "/#{type} FAILED: missing required config value for #{k}" return false end end return true else return true end end |
#config ⇒ Object
17 18 19 |
# File 'lib/scout_apm/reporter.rb', line 17 def config context.config end |
#logger ⇒ Object
21 22 23 |
# File 'lib/scout_apm/reporter.rb', line 21 def logger context.logger end |
#report(payload, headers = {}) ⇒ Object
The fully serialized string payload to be sent
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/scout_apm/reporter.rb', line 26 def report(payload, headers = {}) hosts = determine_hosts if config.value('compress_payload') original_payload_size = payload.length payload, compression_headers = compress_payload(payload) headers.merge!(compression_headers) compress_payload_size = payload.length logger.debug("Original Size: #{original_payload_size} Compressed Size: #{compress_payload_size}") end logger.info("Posting payload to #{hosts.inspect}") post_payload(hosts, payload, headers) end |
#uri(host) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/scout_apm/reporter.rb', line 43 def uri(host) encoded_app_name = CGI.escape(context.environment.application_name) key = config.value('key') case type when :checkin URI.parse("#{host}/apps/checkin.scout?key=#{key}&name=#{encoded_app_name}") when :app_server_load URI.parse("#{host}/apps/app_server_load.scout?key=#{key}&name=#{encoded_app_name}") when :deploy_hook URI.parse("#{host}/apps/deploy.scout?key=#{key}&name=#{encoded_app_name}") when :instant_trace URI.parse("#{host}/apps/instant_trace.scout?key=#{key}&name=#{encoded_app_name}&instant_key=#{instant_key}") when :errors URI.parse("#{host}/apps/error.scout?key=#{key}&name=#{encoded_app_name}") end.tap { |u| logger.debug("Posting to #{u}") } end |