WarpOtlpBridge
Drains converged CRDTs — spans, logs, and metrics — to an OTLP-capable OtlpEdge, reconciling each signal by its own producer-local digest so a re-drain sends only records absent from that digest.
On each drain call, per signal, the bridge:
Snapshots the local CRDT.
Fetches a compact digest from the edge (what this producer already delivered).
Computes the delta — records present locally but absent from the digest (for metrics: series whose value-hash advanced).
Sends only the delta.
For metrics, tells the edge which series are still live (OtlpEdge.retainMetrics), so its record of what it sent stays bounded by the series this producer holds.
Spans additionally carry inferred causal SpanLinks (#846): the bridge runs inferCausalLinks over the full span snapshot (so a predecessor already delivered on an earlier drain still resolves), filters the links to those whose fromSpanId is in the delta, and threads them to OtlpEdge.send for emission on the OTLP Span.links wire field.
Why reconcile-by-digest?
A naive replay would retransmit the entire buffer on every reconnect. A digest-gated delta skips span ids already recorded as delivered. A lost digest or failed acknowledgement can cause another send, which relies on OtlpEdge.send's idempotency requirement. Snapshot merge is separately idempotent by full record equality. Retrying an unstamped export after an indeterminate write and a restart can leave distinct stamped copies with one span id; this bridge does not coalesce them. If their id is absent from the digest, both copies are eligible for delivery.
Best-effort, per-signal isolation
Each signal is drained independently and best-effort: a failing signal never aborts the others, and its CRDT is left intact for the next attempt. The result says which signals failed and why — DrainResult.Partial when some attempted signal succeeded, DrainResult.Failure when none did — so a signal that fails on every drain is visible to the caller, not only in a debug log line.
Parameters
the WarpTelemetry whose span/log/metric exporters are drained.
observation time stamped onto metric points. Required — inject a fixed clock in tests; never a real-dispatcher/wall-clock default that decouples from virtual time.
Samples
val telemetry = WarpTelemetry(
replica = us.tractat.kuilt.crdt.ReplicaId("device-uuid-abc123"),
store = InMemoryDurableStore(),
)
telemetry.recover()
// Export spans while possibly offline — export() succeeds on durable local write.
val span = SpanRecord(
traceId = kotlinx.io.bytestring.ByteString(ByteArray(16) { it.toByte() }),
spanId = kotlinx.io.bytestring.ByteString(ByteArray(8) { it.toByte() }),
parentSpanId = null,
name = "checkout",
kind = SpanKind.CLIENT,
startEpochNanos = 1_000_000_000L,
endEpochNanos = 2_000_000_000L,
)
telemetry.spans.export(span)
// When connectivity returns, drain to the backend. WarpOtlpBridge reconciles each
// signal (spans, logs, metrics) by digest: only records the edge doesn't have are
// sent, and a resend on reconnect cannot double-count. Spans also carry inferred
// causal links (#846). The clock stamps metric observation time.
val bridge = WarpOtlpBridge(telemetry, kotlin.time.Clock.System)
// Wire your OtlpEdge implementation and call drain whenever connectivity returns.
// DrainResult.Success(spansSent, logsSent, metricPointsSent) — no signal failed; 0s mean up to date.
// DrainResult.Partial(counts…, failures) — some signals failed; each SignalFailure names one and its cause.
// DrainResult.Failure(failures) — every attempted signal failed; retry later.
//
// val edge: OtlpEdge = MyKtorOtlpEdge(endpoint = "https://otel-collector.example.com")
// val result: DrainResult = bridge.drain(edge)
println("bridge ready: $bridge")