Class: NewRelic::Agent::InfiniteTracing::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/infinite_tracing/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



36
37
38
# File 'lib/infinite_tracing/connection.rb', line 36

def instance
  @@instance ||= new
end

.metadataObject



58
59
60
# File 'lib/infinite_tracing/connection.rb', line 58

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.



54
55
56
# File 'lib/infinite_tracing/connection.rb', line 54

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.



47
48
49
# File 'lib/infinite_tracing/connection.rb', line 47

def record_spans(client, enumerator, exponential_backoff)
  instance.record_spans(client, enumerator, exponential_backoff)
end

.resetObject



40
41
42
# File 'lib/infinite_tracing/connection.rb', line 40

def reset
  @@instance = new
end

Instance Method Details

#metadataObject

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).



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/infinite_tracing/connection.rb', line 95

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_startedObject

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.



111
112
113
114
115
116
117
118
# File 'lib/infinite_tracing/connection.rb', line 111

def notify_agent_started
  @lock.synchronize do
    @rpc = nil
    @metadata = 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.



73
74
75
76
# File 'lib/infinite_tracing/connection.rb', line 73

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



65
66
67
68
# File 'lib/infinite_tracing/connection.rb', line 65

def record_spans(client, enumerator, exponential_backoff)
  @active_clients[client] = client
  with_reconnection_backoff(exponential_backoff) { rpc.record_span(enumerator, metadata: ) }
end

#rpcObject

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



81
82
83
84
# File 'lib/infinite_tracing/connection.rb', line 81

def rpc
  wait_for_agent_connect
  @rpc ||= Channel.new.stub
end

#wait_for_agent_connectObject



86
87
88
89
90
# File 'lib/infinite_tracing/connection.rb', line 86

def wait_for_agent_connect
  @lock.synchronize do
    @agent_started.wait(@lock) if !@agent_connected
  end
end