Class: ClaudeMemory::OTel::Ingestor

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/otel/ingestor.rb

Overview

Imperative shell for OTel ingestion. Takes the parsed-row hashes produced by OtlpJsonEnvelope and writes them in a single batched transaction. Returns Core::Result so the HTTP server can map outcome to status code without rescue clauses.

The ingestor accepts a ‘:metrics`, `:events`, or `:traces` payload —one kind per call, matching how OTLP/HTTP separates the three endpoints. Wrap each batch in transaction_with_retry so a partial failure mid-insert leaves zero rows behind.

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Ingestor

Returns a new instance of Ingestor.



17
18
19
# File 'lib/claude_memory/otel/ingestor.rb', line 17

def initialize(store)
  @store = store
end

Instance Method Details

#ingest(payload) ⇒ Core::Result

Returns success carries inserted-count Hash; failure carries an error message.

Parameters:

  • payload (Hash)

    one of […], […], […]. Other keys are ignored.

Returns:

  • (Core::Result)

    success carries inserted-count Hash; failure carries an error message



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/claude_memory/otel/ingestor.rb', line 25

def ingest(payload)
  return Core::Result.failure("payload must be a Hash") unless payload.is_a?(Hash)

  counts = {metrics: 0, events: 0, traces: 0}
  @store.transaction_with_retry do
    counts[:metrics] = insert_metrics(payload[:metrics] || payload["metrics"])
    counts[:events] = insert_events(payload[:events] || payload["events"])
    counts[:traces] = insert_traces(payload[:traces] || payload["traces"])
  end
  Core::Result.success(counts)
rescue Sequel::DatabaseError, Extralite::Error, ArgumentError, KeyError => e
  Core::Result.failure(e.message)
end