Skip to main content
Version: SDK ยท v1.1.0

Logs and metrics

The ERPBridge SDK REST surface mirrors the server REST endpoints. All methods use the same typed error hierarchy.

Logsโ€‹

Use client.logs to access the server's structured JSON logs.

const recent = await client.logs.recent() // LogRecord[] โ€” the last buffered records

Use stream() to consume the server's SSE log stream (data: <json>\n\n). The stream reconnects automatically, including after failed connection attempts, until you abort it:

const controller = new AbortController()

for await (const record of client.logs.stream({ signal: controller.signal })) {
console.log(record.level, record.msg)
if (enough) controller.abort() // the iterator finishes cleanly
}

Metricsโ€‹

Use client.metrics to read the server's Prometheus endpoint.

const text = await client.metrics.text() // raw Prometheus text format
const parsed = await client.metrics.parsed() // { families, skipped }

parsed() parses counters, gauges, and histograms, including _bucket, _sum, and _count series, into typed families. It reports unsupported summary and untyped families in skipped instead of throwing.

Healthโ€‹

const status = await client.health() // { status: 'ok' }

Cacheโ€‹

const stats = await client.cache.stats() // { exactKeys, redisMemory }
const flushed = await client.cache.flush({ all: true }) // { deleted, status }

flush() targets a tool, a module, or the whole cache. The endpoints work with the configured Redis backend and the bounded in-memory backend. In-memory mode returns an empty string for redisMemory. A configured but unreachable Redis backend remains selected and returns a typed ServerError. The ERPBridge SDK does not switch to memory mode.

The typed error hierarchyโ€‹

Every REST failure is an ErpbridgeError subclass, such as NotFoundError, RateLimitError (with retryAfter), ServerError (with status and body), or ProtocolError (with a numeric code for malformed server responses). See the quickstart for the full table.