Class: ActiveAgent::Telemetry::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_agent/telemetry/reporter.rb

Overview

Asynchronously reports traces to the telemetry endpoint.

Buffers traces and sends them in batches to reduce network overhead. Uses a background thread for non-blocking transmission.

Examples:

reporter = Reporter.new(configuration)
reporter.report(trace_payload)
reporter.flush  # Send immediately
reporter.shutdown  # Clean shutdown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Reporter

Returns a new instance of Reporter.



24
25
26
27
28
29
30
31
32
33
# File 'lib/active_agent/telemetry/reporter.rb', line 24

def initialize(configuration)
  @configuration = configuration
  @buffer = []
  @mutex = Mutex.new
  @running = false
  @thread = nil
  @shutdown = false

  start_flush_thread if configuration.enabled?
end

Instance Attribute Details

#configurationConfiguration (readonly)

Returns Telemetry configuration.

Returns:



22
23
24
# File 'lib/active_agent/telemetry/reporter.rb', line 22

def configuration
  @configuration
end

Instance Method Details

#flushvoid

This method returns an undefined value.

Flushes all buffered traces immediately.



55
56
57
58
59
# File 'lib/active_agent/telemetry/reporter.rb', line 55

def flush
  @mutex.synchronize do
    flush_buffer
  end
end

#report(trace) ⇒ void

This method returns an undefined value.

Adds a trace to the buffer for transmission.

Parameters:

  • trace (Hash)

    Trace payload



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_agent/telemetry/reporter.rb', line 39

def report(trace)
  return unless configuration.enabled?

  @mutex.synchronize do
    @buffer << trace

    # Flush immediately if buffer is full
    if @buffer.size >= configuration.batch_size
      flush_buffer
    end
  end
end

#shutdownvoid

This method returns an undefined value.

Shuts down the reporter, flushing remaining traces.



64
65
66
67
68
# File 'lib/active_agent/telemetry/reporter.rb', line 64

def shutdown
  @shutdown = true
  flush
  @thread&.join(5) # Wait up to 5 seconds for thread to finish
end