Class: Instana::Backend::ServerlessAgent

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

Overview

Since:

  • 1.197.0

Constant Summary collapse

DEFAULT_SECRETS =

Since:

  • 1.197.0

'contains-ignore-case:key,password,secret'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshots, timer_class: Concurrent::TimerTask, processor: ::Instana.processor, logger: ::Instana.logger, backend_uri: ENV['INSTANA_ENDPOINT_URL'], secrets: ENV.fetch('INSTANA_SECRETS', DEFAULT_SECRETS), headers: ENV.fetch('INSTANA_EXTRA_HTTP_HEADERS', '')) ⇒ ServerlessAgent

rubocop:disable Metrics/ParameterLists

Since:

  • 1.197.0



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/instana/backend/serverless_agent.rb', line 12

def initialize(snapshots,
               timer_class: Concurrent::TimerTask,
               processor: ::Instana.processor,
               logger: ::Instana.logger,
               backend_uri: ENV['INSTANA_ENDPOINT_URL'],
               secrets: ENV.fetch('INSTANA_SECRETS', DEFAULT_SECRETS), headers: ENV.fetch('INSTANA_EXTRA_HTTP_HEADERS', ''))
  @snapshots = snapshots
  @processor = processor
  @logger = logger
  @timer = timer_class.new(execution_interval: 1, run_now: true) { send_bundle }
  @backend_uri = URI(backend_uri)
  @client = Backend::RequestClient.new(@backend_uri.host, @backend_uri.port, use_ssl: @backend_uri.scheme == "https")
  @secrets = secrets
  @headers = headers
end

Instance Attribute Details

#timerObject (readonly)

Since:

  • 1.197.0



9
10
11
# File 'lib/instana/backend/serverless_agent.rb', line 9

def timer
  @timer
end

Instance Method Details

#extra_headersArray

Returns extra headers to include in the trace.

Returns:

  • (Array)

    extra headers to include in the trace

Since:

  • 1.197.0



56
57
58
# File 'lib/instana/backend/serverless_agent.rb', line 56

def extra_headers
  @headers.split(';')
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



39
40
41
# File 'lib/instana/backend/serverless_agent.rb', line 39

def ready?
  true
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



61
62
63
64
# File 'lib/instana/backend/serverless_agent.rb', line 61

def secret_values
  matcher, *keys = @secrets.split(/[:,]/)
  {'matcher' => matcher, 'list' => keys}
end

#send_bundleObject

Since:

  • 1.197.0



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/instana/backend/serverless_agent.rb', line 66

def send_bundle
  spans = @processor.queued_spans
  bundle = {
    spans: spans,
    metrics: {
      plugins: agent_snapshots
    }
  }

  path = "#{@backend_uri.path}/bundle"
  response = @client.send_request('POST', path, bundle, request_headers)

  return if response.ok?

  @logger.warn("Recived a `#{response.code}` when sending data.")
end

#setupObject

rubocop:enable Metrics/ParameterLists

Since:

  • 1.197.0



29
# File 'lib/instana/backend/serverless_agent.rb', line 29

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/instana/backend/serverless_agent.rb', line 44

def source
  snapshot = @snapshots.detect { |s| s.respond_to?(:source) }

  if snapshot
    snapshot.source
  else
    @logger.warn('Unable to find a snapshot which provides a source.')
    {}
  end
end

#spawn_background_threadObject Also known as: start, after_fork

Since:

  • 1.197.0



31
32
33
# File 'lib/instana/backend/serverless_agent.rb', line 31

def spawn_background_thread
  @timer.execute
end