Class: Confium::Audit::OtlpSink

Inherits:
Sink
  • Object
show all
Defined in:
lib/confium/audit/otlp_sink.rb

Overview

Exports audit records to an OpenTelemetry Collector over OTLP/HTTP JSON (the logs signal — an audit event is a log record, not a span).

Confium::Audit.sink = Confium::Audit::OtlpSink.new(
endpoint: 'http://localhost:4318/v1/logs',
headers: { 'Authorization' => "Bearer #{token}" },
service_name: 'confium-issuer'
)

Delivery is synchronous per record, retried with exponential backoff (retries: attempts after the first, base doubled per attempt). After the final failure the record is dropped with a $stderr report — the audit core's policy: a telemetry outage must never break signing. stdlib only.

Constant Summary collapse

DEFAULT_ENDPOINT =
'http://localhost:4318/v1/logs'
SEVERITY =

INFO / ERROR

{ 'success' => 9, 'failure' => 17, 'error' => 17 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Sink

#call

Constructor Details

#initialize(endpoint: DEFAULT_ENDPOINT, headers: {}, service_name: 'confium', timeout: 5, retries: 2, retry_base: 0.1) ⇒ OtlpSink

Returns a new instance of OtlpSink.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/confium/audit/otlp_sink.rb', line 28

def initialize(endpoint: DEFAULT_ENDPOINT, headers: {}, service_name: 'confium', timeout: 5,
               retries: 2, retry_base: 0.1)
  super()
  @uri = URI.parse(endpoint)
  @headers = headers
  @service_name = service_name
  @timeout = timeout
  @retries = retries
  @retry_base = retry_base
  @dropped = 0
end

Instance Attribute Details

#droppedObject (readonly)

Records dropped after failed delivery (diagnostic only).



41
42
43
# File 'lib/confium/audit/otlp_sink.rb', line 41

def dropped
  @dropped
end

Instance Method Details

#closeObject



51
# File 'lib/confium/audit/otlp_sink.rb', line 51

def close; end

#write(record) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/confium/audit/otlp_sink.rb', line 43

def write(record)
  payload = envelope(record)
  deliver(JSON.generate(payload))
rescue StandardError => e
  @dropped += 1
  warn "confium: OTLP delivery failed, audit record dropped (##{@dropped}): #{e.class}: #{e.message}"
end