Module: NewRelic::Agent::InfiniteTracing::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/infinite_tracing/config.rb

Constant Summary collapse

TRACE_OBSERVER_NOT_CONFIGURED_ERROR =
"Trace Observer host not configured!"

Instance Method Summary collapse

Instance Method Details

#distributed_tracing_enabled?Boolean

Distributed Tracing must be enabled for Infinite Tracing

Returns:

  • (Boolean)


33
34
35
# File 'lib/infinite_tracing/config.rb', line 33

def distributed_tracing_enabled?
  NewRelic::Agent.config[:'distributed_tracing.enabled']
end

#enabled?Boolean

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.

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/infinite_tracing/config.rb', line 26

def enabled?
  distributed_tracing_enabled? &&
    span_events_enabled? &&
    trace_observer_configured?
end

#local?Boolean

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.

Returns:

  • (Boolean)


46
47
48
# File 'lib/infinite_tracing/config.rb', line 46

def local?
  test_framework?
end

#port_from_host_entryObject

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.



63
64
65
66
67
68
69
# 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?Boolean

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

Returns:

  • (Boolean)


17
18
19
# File 'lib/infinite_tracing/config.rb', line 17

def should_load?
  test_framework? || trace_observer_configured?
end

#span_events_enabled?Boolean

Span Events must be enabled for Infinite Tracing

Returns:

  • (Boolean)


38
39
40
# File 'lib/infinite_tracing/config.rb', line 38

def span_events_enabled?
  NewRelic::Agent.config[:'span_events.enabled']
end

#span_events_queue_sizeObject

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



100
101
102
# File 'lib/infinite_tracing/config.rb', line 100

def span_events_queue_size
  NewRelic::Agent.config[:'span_events.queue_size']
end

#test_framework?Boolean

Returns TRUE if we're running in a test environment

Returns:

  • (Boolean)


105
106
107
# File 'lib/infinite_tracing/config.rb', line 105

def test_framework?
  NewRelic::Agent.config[:framework] == :test
end

#trace_observer_configured?Boolean

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

Returns:

  • (Boolean)


110
111
112
# File 'lib/infinite_tracing/config.rb', line 110

def trace_observer_configured?
  trace_observer_host != NewRelic::EMPTY_STR
end

#trace_observer_hostObject



55
56
57
# 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_portObject

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



94
95
96
# File 'lib/infinite_tracing/config.rb', line 94

def trace_observer_host_and_port
  "#{trace_observer_host}:#{trace_observer_port}"
end

#trace_observer_portObject

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.



73
74
75
# 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_schemeObject

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



79
80
81
# File 'lib/infinite_tracing/config.rb', line 79

def trace_observer_scheme
  local? ? NewRelic::HTTP : NewRelic::HTTPS
end

#trace_observer_uriObject

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



84
85
86
87
88
89
90
91
# 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) ⇒ Object

removes the scheme and port from a host entry.



51
52
53
# File 'lib/infinite_tracing/config.rb', line 51

def without_scheme_or_port(url)
  url.gsub(%r{^https?://|:\d+$}, '')
end