Class: NewRelic::Agent::InfiniteTracing::Connection
- Inherits:
-
Object
- Object
- NewRelic::Agent::InfiniteTracing::Connection
- Defined in:
- lib/infinite_tracing/connection.rb
Class Method Summary collapse
- .instance ⇒ Object
- .metadata ⇒ Object
-
.record_span_batches(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in.
-
.record_spans(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in.
- .reset ⇒ Object
Instance Method Summary collapse
-
#metadata ⇒ Object
The metadata for the RPC calls is a blocking call waiting for the Agent to connect and receive the server side configuration, which contains the license_key as well as the agent_id (agent_run_token).
-
#notify_agent_started ⇒ Object
Initializes rpc so we can get a Channel and Stub (connect to gRPC server) Initializes metadata so we use newest values in establishing channel Sets the agent_connected flag and signals the agent started so any waiting locks (rpc calls ahead of the agent connecting) can proceed.
-
#record_span_batches(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in.
-
#record_spans(client, enumerator, exponential_backoff) ⇒ Object
We attempt to connect and record spans with reconnection backoff in order to deal with unavailable errors coming from the stub being created and record_span call.
-
#rpc ⇒ Object
Acquires the new channel stub for the RPC calls.
- #wait_for_agent_connect ⇒ Object
Class Method Details
.instance ⇒ Object
35 36 37 |
# File 'lib/infinite_tracing/connection.rb', line 35 def instance @@instance ||= new end |
.metadata ⇒ Object
57 58 59 |
# File 'lib/infinite_tracing/connection.rb', line 57 def instance. end |
.record_span_batches(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in. We track this so we're able to signal the client to restart when connectivity to the server is disrupted.
53 54 55 |
# File 'lib/infinite_tracing/connection.rb', line 53 def record_span_batches client, enumerator, exponential_backoff instance.record_span_batch client, enumerator, exponential_backoff end |
.record_spans(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in. We track this so we're able to signal the client to restart when connectivity to the server is disrupted.
46 47 48 |
# File 'lib/infinite_tracing/connection.rb', line 46 def record_spans client, enumerator, exponential_backoff instance.record_spans client, enumerator, exponential_backoff end |
.reset ⇒ Object
39 40 41 |
# File 'lib/infinite_tracing/connection.rb', line 39 def reset @@instance = new end |
Instance Method Details
#metadata ⇒ Object
The metadata for the RPC calls is a blocking call waiting for the Agent to connect and receive the server side configuration, which contains the license_key as well as the agent_id (agent_run_token).
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/infinite_tracing/connection.rb', line 94 def return @metadata if @metadata @lock.synchronize do @metadata = { "license_key" => license_key, "agent_run_token" => agent_id } @metadata.merge!(request_headers_map) end end |
#notify_agent_started ⇒ Object
Initializes rpc so we can get a Channel and Stub (connect to gRPC server) Initializes metadata so we use newest values in establishing channel Sets the agent_connected flag and signals the agent started so any waiting locks (rpc calls ahead of the agent connecting) can proceed.
110 111 112 113 114 115 116 117 118 |
# File 'lib/infinite_tracing/connection.rb', line 110 def notify_agent_started @lock.synchronize do @rpc = nil @metadata = nil @agent_connected = true @agent_started.signal end @active_clients.each_value(&:restart) end |
#record_span_batches(client, enumerator, exponential_backoff) ⇒ Object
RPC calls will pass the calling client instance in. We track this so we're able to signal the client to restart when connectivity to the server is disrupted.
72 73 74 75 |
# File 'lib/infinite_tracing/connection.rb', line 72 def record_span_batches client, enumerator, exponential_backoff @active_clients[client] = client with_reconnection_backoff(exponential_backoff) { rpc.record_span_batch enumerator, metadata: } end |
#record_spans(client, enumerator, exponential_backoff) ⇒ Object
We attempt to connect and record spans with reconnection backoff in order to deal with unavailable errors coming from the stub being created and record_span call
64 65 66 67 |
# File 'lib/infinite_tracing/connection.rb', line 64 def record_spans client, enumerator, exponential_backoff @active_clients[client] = client with_reconnection_backoff(exponential_backoff) { rpc.record_span enumerator, metadata: } end |
#rpc ⇒ Object
Acquires the new channel stub for the RPC calls. We attempt to connect and record spans with reconnection backoff in order to deal with unavailable errors coming from the stub being created and record_span call
80 81 82 83 |
# File 'lib/infinite_tracing/connection.rb', line 80 def rpc wait_for_agent_connect @rpc ||= Channel.new.stub end |
#wait_for_agent_connect ⇒ Object
85 86 87 88 89 |
# File 'lib/infinite_tracing/connection.rb', line 85 def wait_for_agent_connect @lock.synchronize do @agent_started.wait(@lock) if !@agent_connected end end |