Class: NewRelic::Agent::InfiniteTracing::Connection
- Inherits:
-
Object
- Object
- NewRelic::Agent::InfiniteTracing::Connection
- Defined in:
- lib/infinite_tracing/connection.rb
Constant Summary collapse
- GZIP_METADATA =
{'grpc-internal-encoding-request' => 'gzip', 'grpc-encoding' => 'gzip', 'grpc-accept-encoding' => ['gzip'], 'content-coding' => 'gzip', 'content-encoding' => 'gzip'}.freeze
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
-
#merge_gzip_metadata ⇒ Object
If (gzip based) compression is enabled, explicitly provide all relevant metadata.
-
#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
41 42 43 |
# File 'lib/infinite_tracing/connection.rb', line 41 def instance @@instance ||= new end |
.metadata ⇒ Object
63 64 65 |
# File 'lib/infinite_tracing/connection.rb', line 63 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.
59 60 61 |
# File 'lib/infinite_tracing/connection.rb', line 59 def record_span_batches(client, enumerator, exponential_backoff) instance.record_span_batches(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.
52 53 54 |
# File 'lib/infinite_tracing/connection.rb', line 52 def record_spans(client, enumerator, exponential_backoff) instance.record_spans(client, enumerator, exponential_backoff) end |
.reset ⇒ Object
45 46 47 |
# File 'lib/infinite_tracing/connection.rb', line 45 def reset @@instance = new end |
Instance Method Details
#merge_gzip_metadata ⇒ Object
If (gzip based) compression is enabled, explicitly provide all relevant metadata
115 116 117 118 119 |
# File 'lib/infinite_tracing/connection.rb', line 115 def return unless Config.compression_enabled? .merge!(GZIP_METADATA) end |
#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).
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/infinite_tracing/connection.rb', line 100 def return if @lock.synchronize do = { 'license_key' => license_key, 'agent_run_token' => agent_id } .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.
125 126 127 128 129 130 131 132 |
# File 'lib/infinite_tracing/connection.rb', line 125 def notify_agent_started @lock.synchronize do @rpc = nil = nil @agent_connected = true @agent_started.signal end 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.
78 79 80 81 |
# File 'lib/infinite_tracing/connection.rb', line 78 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
70 71 72 73 |
# File 'lib/infinite_tracing/connection.rb', line 70 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
86 87 88 89 |
# File 'lib/infinite_tracing/connection.rb', line 86 def rpc wait_for_agent_connect @rpc ||= Channel.new.stub end |
#wait_for_agent_connect ⇒ Object
91 92 93 94 95 |
# File 'lib/infinite_tracing/connection.rb', line 91 def wait_for_agent_connect @lock.synchronize do @agent_started.wait(@lock) if !@agent_connected end end |