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



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

def instance
  @@instance ||= new
end

.metadataObject



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



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

.resetObject



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

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



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



110
111
112
113
114
115
116
117
# 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
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

#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



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_connectObject



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