Class: Instana::Backend::HostAgent
- Inherits:
-
Object
- Object
- Instana::Backend::HostAgent
- Defined in:
- lib/instana/backend/host_agent.rb
Overview
Instance Attribute Summary collapse
- #client ⇒ Object readonly
- #future ⇒ Object readonly
Instance Method Summary collapse
- #announce ⇒ Object (also: #after_fork)
-
#extra_headers ⇒ Array
Extra headers to capture with HTTP spans.
-
#initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger) ⇒ HostAgent
constructor
A new instance of HostAgent.
-
#ready? ⇒ Boolean
True if the agent able to send spans to the backend.
-
#secret_values ⇒ Hash
Values which are removed from urls sent to the backend.
- #setup ⇒ Object
-
#source ⇒ Hash, NilClass
The backend friendly description of the current in process collector.
- #spawn_background_thread ⇒ Object (also: #start)
Constructor Details
#initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger) ⇒ HostAgent
Returns a new instance of HostAgent.
10 11 12 13 14 15 16 17 |
# File 'lib/instana/backend/host_agent.rb', line 10 def initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger) @discovery = discovery @logger = logger @future = nil @client = nil # Timer task to poll for agent liveliness @agent_connection_task = Concurrent::TimerTask.new(execution_interval: 75) { announce } end |
Instance Attribute Details
#client ⇒ Object (readonly)
8 9 10 |
# File 'lib/instana/backend/host_agent.rb', line 8 def client @client end |
#future ⇒ Object (readonly)
8 9 10 |
# File 'lib/instana/backend/host_agent.rb', line 8 def future @future end |
Instance Method Details
#announce ⇒ Object Also known as: after_fork
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/instana/backend/host_agent.rb', line 31 def announce @client = with_timeout { HostAgentLookup.new.call } # Shuts down the connection task based on agent connection client. @client ? @agent_connection_task.shutdown : @agent_connection_task.execute # Do not continue further if the agent is down/connection to the agent is unsuccessfull return nil unless @client begin @discovery.send(:observers)&.send(:notify_and_delete_observers, Time.now, nil, nil) ensure @discovery.delete_observers end @discovery .with_observer(HostAgentActivationObserver.new(@client, @discovery)) .with_observer(HostAgentReportingObserver.new(@client, @discovery)) @discovery.swap { nil } @client end |
#extra_headers ⇒ Array
Returns extra headers to capture with HTTP spans.
67 68 69 70 71 72 73 74 75 |
# File 'lib/instana/backend/host_agent.rb', line 67 def extra_headers if discovery_value['tracing'] # Starting with discovery version 1.6.4, this value is in tracing.extra-http-headers. discovery_value['tracing']['extra-http-headers'] else # Legacy fallback for discovery versions <= 1.6.3. discovery_value['extraHeaders'] end end |
#ready? ⇒ Boolean
Returns true if the agent able to send spans to the backend.
54 55 56 |
# File 'lib/instana/backend/host_agent.rb', line 54 def ready? ENV.key?('INSTANA_TEST') || !@discovery.value.nil? end |
#secret_values ⇒ Hash
Returns values which are removed from urls sent to the backend.
78 79 80 |
# File 'lib/instana/backend/host_agent.rb', line 78 def secret_values discovery_value['secrets'] end |
#setup ⇒ Object
19 |
# File 'lib/instana/backend/host_agent.rb', line 19 def setup; end |
#source ⇒ Hash, NilClass
Returns the backend friendly description of the current in process collector.
59 60 61 62 63 64 |
# File 'lib/instana/backend/host_agent.rb', line 59 def source { e: discovery_value['pid'], h: discovery_value['agentUuid'] }.reject { |_, v| v.nil? } end |
#spawn_background_thread ⇒ Object Also known as: start
21 22 23 24 25 26 27 |
# File 'lib/instana/backend/host_agent.rb', line 21 def spawn_background_thread return if ENV.key?('INSTANA_TEST') @future = Concurrent::Promises.future do announce end end |