module NewRelic::Agent::InfiniteTracing::Config

Constants

TRACE_OBSERVER_NOT_CONFIGURED_ERROR

Public Instance Methods

distributed_tracing_enabled?() click to toggle source

Distributed Tracing must be enabled for Infinite Tracing

# File lib/infinite_tracing/config.rb, line 33
def distributed_tracing_enabled?
  NewRelic::Agent.config[:'distributed_tracing.enabled']
end
enabled?() click to toggle source

Infinite Tracing support is enabled when the following conditions are true:

a) Distributed tracing is enabled in the agent, AND
b) Span events are enabled in the agent, both by client side configuration
   AND the collect_span_events connect response field, AND
c) A Trace Observer host is configured by setting infinite_tracing.trace_observer.host.
# File lib/infinite_tracing/config.rb, line 26
def enabled?
  distributed_tracing_enabled? && 
  span_events_enabled? && 
  trace_observer_configured?
end
local?() click to toggle source

running locally is akin to communicating with the gRPC server with an unencrypted channel. Generally, this is not allowed by the agent in normal use-cases. The only known use-case for this is when streaming under TEST conditions.

# File lib/infinite_tracing/config.rb, line 46
def local?
  test_framework?
end
port_from_host_entry() click to toggle source

If the port is declared on the host entry, it overrides the port entry because otherwise we'd need to figure out if user supplied the port or if the default source config set the port. To help with debugging configuration issues, we log whenever the port entry is overriden by the presence of the port on the host entry.

# File lib/infinite_tracing/config.rb, line 63
def port_from_host_entry
  port_str = NewRelic::Agent.config[:'infinite_tracing.trace_observer.host'].scan(%r{:(\d+)$}).flatten
  if port = (port_str[0] and port_str[0].to_i)
    NewRelic::Agent.logger.warn(":'infinite_tracing.trace_observer.port' is ignored if present because :'infinite_tracing.trace_observer.host' specifies the port")
    return port
  end
end
should_load?() click to toggle source

We only want to load the infinite tracing gem's files when

a) we're inside test framework and running tests
b) the trace observer host is configured
# File lib/infinite_tracing/config.rb, line 17
def should_load?
  test_framework? || trace_observer_configured?
end
span_events_enabled?() click to toggle source

Span Events must be enabled for Infinite Tracing

# File lib/infinite_tracing/config.rb, line 38
def span_events_enabled?
  NewRelic::Agent.config[:'span_events.enabled']
end
span_events_queue_size() click to toggle source

The maximum number of span events the Streaming Buffer can hold when buffering to stream across the gRPC channel.

# File lib/infinite_tracing/config.rb, line 100
def span_events_queue_size
  NewRelic::Agent.config[:'span_events.queue_size']
end
test_framework?() click to toggle source

Returns TRUE if we're running in a test environment

# File lib/infinite_tracing/config.rb, line 105
def test_framework?
  NewRelic::Agent.config[:framework] == :test
end
trace_observer_configured?() click to toggle source

Infinite Tracing is configured when a non empty string is set as the host

# File lib/infinite_tracing/config.rb, line 110
def trace_observer_configured?
  trace_observer_host != NewRelic::EMPTY_STR
end
trace_observer_host() click to toggle source
# File lib/infinite_tracing/config.rb, line 55
def trace_observer_host
  without_scheme_or_port NewRelic::Agent.config[:'infinite_tracing.trace_observer.host']
end
trace_observer_host_and_port() click to toggle source

returns host and port together expressed as hostname:port string.

# File lib/infinite_tracing/config.rb, line 94
def trace_observer_host_and_port
  "#{trace_observer_host}:#{trace_observer_port}"
end
trace_observer_port() click to toggle source

This is the port the trace observer is listening on. It can be supplied as a suffix on the host entry or via the separate port entry.

# File lib/infinite_tracing/config.rb, line 73
def trace_observer_port
  port_from_host_entry || NewRelic::Agent.config[:'infinite_tracing.trace_observer.port']
end
trace_observer_scheme() click to toggle source

The scheme is based on whether the Trace Observer is running locally or remotely. Remote unsecure (unencypted) streaming is disallowed!

# File lib/infinite_tracing/config.rb, line 79
def trace_observer_scheme
  local? ? NewRelic::HTTP : NewRelic::HTTPS
end
trace_observer_uri() click to toggle source

The uniform resource identifier of the Trace Observer host constructed from all the parts.

# File lib/infinite_tracing/config.rb, line 84
def trace_observer_uri
  if trace_observer_configured?
    URI("#{trace_observer_scheme}://#{trace_observer_host_and_port}")
  else
    NewRelic::Agent.logger.error TRACE_OBSERVER_NOT_CONFIGURED_ERROR
    raise TRACE_OBSERVER_NOT_CONFIGURED_ERROR
  end
end
without_scheme_or_port(url) click to toggle source

removes the scheme and port from a host entry.

# File lib/infinite_tracing/config.rb, line 51
def without_scheme_or_port url
  url.gsub(%r{^https?://|:\d+$}, '')
end