Class: ActiveAgents::Telemetry::Reporter
- Inherits:
-
Object
- Object
- ActiveAgents::Telemetry::Reporter
- Defined in:
- lib/activeagents/telemetry/reporter.rb
Overview
Delivers traces to the configured endpoint.
Telemetry is never worth breaking an app over, so every failure path here ends in a log line: a bad endpoint, a down collector, a serialization bug in an adapter, and a nil api_key all degrade to "no traces" rather than an exception in the caller's request cycle.
Delivery is fire-and-forget on a thread by default. Pass async: false
for tests, or for scripts short enough that the process may exit before a
background thread flushes.
Direct Known Subclasses
Constant Summary collapse
- SDK_NAME =
"activeagents-telemetry"
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#initialize(configuration, sdk_name: SDK_NAME, sdk_version: VERSION, sample: true) ⇒ Reporter
constructor
A new instance of Reporter.
- #report(traces) ⇒ void
-
#report_now(traces) ⇒ Object
Blocking delivery, for tests and for at-exit flushes.
Constructor Details
#initialize(configuration, sdk_name: SDK_NAME, sdk_version: VERSION, sample: true) ⇒ Reporter
Returns a new instance of Reporter.
29 30 31 32 33 34 |
# File 'lib/activeagents/telemetry/reporter.rb', line 29 def initialize(configuration, sdk_name: SDK_NAME, sdk_version: VERSION, sample: true) @configuration = configuration @sdk_name = sdk_name @sdk_version = sdk_version @sample = sample end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
22 23 24 |
# File 'lib/activeagents/telemetry/reporter.rb', line 22 def configuration @configuration end |
Instance Method Details
#report(traces) ⇒ void
This method returns an undefined value.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/activeagents/telemetry/reporter.rb', line 39 def report(traces) traces = normalize(traces) return if traces.empty? return unless configuration.enabled? && configuration.configured? return unless sample_trace? body = payload_for(traces) configuration.async? ? Thread.new { deliver(body) } : deliver(body) nil rescue StandardError => e log("failed to build trace payload: #{e.class}: #{e.}") nil end |
#report_now(traces) ⇒ Object
Blocking delivery, for tests and for at-exit flushes.
54 55 56 57 58 59 60 |
# File 'lib/activeagents/telemetry/reporter.rb', line 54 def report_now(traces) traces = normalize(traces) return if traces.empty? return unless configuration.enabled? && configuration.configured? deliver(payload_for(traces)) end |