@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / consoleDebugSink

Function: consoleDebugSink()

consoleDebugSink(opts?): (e) => void

Defined in: packages/sdk/src/debug.ts:328

Ready-made console renderer for ClientConfig.debug — prints the event stream as an indented span tree, the zero-setup way to watch what a client is doing.

Output shape — opens a span, closes it with its duration, · is a mid-span annotation, and log events print flat with their scope:

text
[sdk] ▶ trader.placeOrder { params: { pool: "0x…", side: "BUY_YES" } }
[sdk]   ▶ trade.execute { functionName: "placeBinaryOrder", … }
[sdk] liveTail applying logs { received: 3, … }
[sdk]     · trade.execute { hash: "0x…" }
[sdk]   ◀ trade.execute 38.2ms
[sdk] ◀ trader.placeOrder 41.0ms

Details

Indentation is reconstructed from parentId, so trees stay correct when concurrent operations interleave. warn-level logs and failed spans route to console.warn; everything else goes to console.debug (in browser devtools, enable the Verbose level to see it).

Gotchas

The sink keeps per-span depth state, so build one per client rather than sharing an instance.

Parameters

opts?

prefix replaces the leading [sdk] tag on every line — useful to tell two clients apart in one console.

prefix?

string

Returns

A sink to pass as ClientConfig.debug.

(e) => void

See

debugCollector for capturing events in tests instead of printing.

Example

Opt in from devtools without redeploying — localStorage.setItem("sdk-debug", "1") and reload:

ts
const exchange = new SomniaMarkets({
  ...config,
  debug: localStorage.getItem("sdk-debug") ? consoleDebugSink() : undefined,
});