Class: ActiveAgent::Telemetry::Reporter
- Inherits:
-
Object
- Object
- ActiveAgent::Telemetry::Reporter
- 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.
Instance Attribute Summary collapse
-
#configuration ⇒ Configuration
readonly
Telemetry configuration.
Instance Method Summary collapse
-
#flush ⇒ void
Flushes all buffered traces immediately.
-
#initialize(configuration) ⇒ Reporter
constructor
A new instance of Reporter.
-
#report(trace) ⇒ void
Adds a trace to the buffer for transmission.
-
#shutdown ⇒ void
Shuts down the reporter, flushing remaining traces.
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
#configuration ⇒ Configuration (readonly)
Returns Telemetry configuration.
22 23 24 |
# File 'lib/active_agent/telemetry/reporter.rb', line 22 def configuration @configuration end |
Instance Method Details
#flush ⇒ void
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.
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 |
#shutdown ⇒ void
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 |