Class: ActiveAgents::Telemetry::Reporter

Inherits:
Object
  • Object
show all
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

BatchingReporter

Constant Summary collapse

SDK_NAME =
"activeagents-telemetry"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, sdk_name: SDK_NAME, sdk_version: VERSION, sample: true) ⇒ Reporter

Returns a new instance of Reporter.

Parameters:

  • sdk_name (String) (defaults to: SDK_NAME)

    overridden by adapters so ingest can tell which integration produced a trace.

  • sample (Boolean) (defaults to: true)

    pass false when the caller already applied head-based sampling at trace creation — sampling twice compounds the rate to rate².



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

#configurationObject (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.

Parameters:

  • traces (Trace, Hash, Array<Trace, Hash>)

    traces to deliver — Trace objects or already-serialized trace hashes



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.message}")
  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