Class: Instana::Backend::ServerlessAgent
- Inherits:
-
Object
- Object
- Instana::Backend::ServerlessAgent
- Defined in:
- lib/instana/backend/serverless_agent.rb
Overview
Constant Summary collapse
- DEFAULT_SECRETS =
'contains-ignore-case:key,password,secret'.freeze
Instance Attribute Summary collapse
- #timer ⇒ Object readonly
Instance Method Summary collapse
-
#extra_headers ⇒ Array
Extra headers to include in the trace.
-
#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
constructor
rubocop:disable Metrics/ParameterLists.
-
#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.
- #send_bundle ⇒ Object
-
#setup ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#source ⇒ Hash, NilClass
The backend friendly description of the current in process collector.
- #spawn_background_thread ⇒ Object (also: #start, #after_fork)
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
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
#timer ⇒ Object (readonly)
9 10 11 |
# File 'lib/instana/backend/serverless_agent.rb', line 9 def timer @timer end |
Instance Method Details
#extra_headers ⇒ Array
Returns extra headers to include in the trace.
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.
39 40 41 |
# File 'lib/instana/backend/serverless_agent.rb', line 39 def ready? true end |
#secret_values ⇒ Hash
Returns values which are removed from urls sent to the backend.
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_bundle ⇒ Object
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 |
#setup ⇒ Object
rubocop:enable Metrics/ParameterLists
29 |
# File 'lib/instana/backend/serverless_agent.rb', line 29 def setup; end |
#source ⇒ Hash, NilClass
Returns the backend friendly description of the current in process collector.
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_thread ⇒ Object Also known as: start, after_fork
31 32 33 |
# File 'lib/instana/backend/serverless_agent.rb', line 31 def spawn_background_thread @timer.execute end |