Class: Instana::Backend::HostAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/backend/host_agent.rb

Overview

Since:

  • 1.197.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discovery: Concurrent::Atom.new(nil), logger: ::Instana.logger) ⇒ HostAgent

Returns a new instance of HostAgent.

Since:

  • 1.197.0



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

#clientObject (readonly)

Since:

  • 1.197.0



8
9
10
# File 'lib/instana/backend/host_agent.rb', line 8

def client
  @client
end

#futureObject (readonly)

Since:

  • 1.197.0



8
9
10
# File 'lib/instana/backend/host_agent.rb', line 8

def future
  @future
end

Instance Method Details

#announceObject Also known as: after_fork

Since:

  • 1.197.0



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_headersArray

Returns extra headers to capture with HTTP spans.

Returns:

  • (Array)

    extra headers to capture with HTTP spans

Since:

  • 1.197.0



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.

Returns:

  • (Boolean)

    true if the agent able to send spans to the backend

Since:

  • 1.197.0



54
55
56
# File 'lib/instana/backend/host_agent.rb', line 54

def ready?
  ENV.key?('INSTANA_TEST') || !@discovery.value.nil?
end

#secret_valuesHash

Returns values which are removed from urls sent to the backend.

Returns:

  • (Hash)

    values which are removed from urls sent to the backend

Since:

  • 1.197.0



78
79
80
# File 'lib/instana/backend/host_agent.rb', line 78

def secret_values
  discovery_value['secrets']
end

#setupObject

Since:

  • 1.197.0



19
# File 'lib/instana/backend/host_agent.rb', line 19

def setup; end

#sourceHash, NilClass

Returns the backend friendly description of the current in process collector.

Returns:

  • (Hash, NilClass)

    the backend friendly description of the current in process collector

Since:

  • 1.197.0



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_threadObject Also known as: start

Since:

  • 1.197.0



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