Class: Prescient::Agent::AuditLog
- Inherits:
-
Object
- Object
- Prescient::Agent::AuditLog
- Defined in:
- lib/prescient/agent/audit_log.rb
Overview
Persists safe Agent telemetry events as newline-delimited JSON.
Constant Summary collapse
- FIELDS =
Telemetry keys permitted in durable audit records.
%i[event loop loops_run actions success phase error].freeze
Instance Method Summary collapse
-
#call(event) ⇒ void
Persist one allowlisted telemetry event.
-
#initialize(path: nil, io: nil) ⇒ AuditLog
constructor
A new instance of AuditLog.
Constructor Details
#initialize(path: nil, io: nil) ⇒ AuditLog
Returns a new instance of AuditLog.
17 18 19 20 21 22 23 |
# File 'lib/prescient/agent/audit_log.rb', line 17 def initialize(path: nil, io: nil) raise ArgumentError, "provide path or io, not both" if path && io raise ArgumentError, "path or io is required" unless path || io @io = io || File.open(path, "a") @lock = Monitor.new end |
Instance Method Details
#call(event) ⇒ void
This method returns an undefined value.
Persist one allowlisted telemetry event.
28 29 30 31 32 33 34 |
# File 'lib/prescient/agent/audit_log.rb', line 28 def call(event) record = event.slice(*FIELDS).merge(timestamp: Time.now.utc.iso8601) @lock.synchronize do @io.write("#{JSON.generate(record)}\n") @io.flush if @io.respond_to?(:flush) end end |