Skip to content
Wasm logging and observability approaches

Wasm logging and observability approaches

Research for Host-mediated App logs/metrics/traces (see root CONTEXT.md).
Question: how do Wasm hosts, frameworks, and standards expect guests to emit observability signals — and which patterns fit a multi-App Host that isolates installs and must not leak Host internals?

Executive finding

Three layers show up repeatedly:

  1. Leveled log API (wasi:logging) — guest calls log(level, context, message); host implements the import and owns storage/routing.
  2. Byte streams (wasi:cli/stdout + stderr) — unstructured bytes; host chooses whether to sink, capture, or inherit process stdio.
  3. Full OTel signals (wasi:otel) — guest buffers traces/metrics/logs and exports to the host (not over the network from the guest); host ties spans into host-side traces and may forward via OTLP.

For a multi-App personal-cloud Host, the durable pattern is Host-mediated imports only: attribute every signal to an App install id, never give guests ambient collector endpoints or Host process log sinks, and treat browser client Wasm the same way (Shell bridge import → Shell → Host), not DevTools console as the product surface.


Summary matrix

Approach Maturity What guest emits Who exports / stores Multi-App attribution Leak risk if naïve
wasi:logging Phase 1 draft Level + context + message string Host implements log Host stamps install id / component id on receive Mixing guest logs into Host process logger without labels; exposing Host log files to Apps
wasi:cli stdout/stderr WASI 0.2 stable Raw bytes on output streams Host wires streams (MemoryOutputPipe, inherit, sink) Only if Host captures per Store/instance inherit_stdio into Host process; shared pipes across installs
Host-side OTel (no guest API) Product practice (Spin, wasmCloud) Nothing structured from guest beyond stdout/logs Host instruments runtime + may scrape stdout Host spans tagged by app Guests never see collectors — good; App-authored spans absent
wasi:otel Phase 2 proposal; experimental in Spin/wash Traces, metrics, logs via WIT mirroring OTel Guest buffers → host export; host may OTLP Host can parent guest spans under request spans Giving guests HTTP to collectors; trusting guest resource attributes blindly
Browser worker console Platform API DevTools console lines Tab DevTools (not Instance ops) None for Host operators Treating console as security boundary; ambient fetch in glue

wasi:logging (draft)

Spec

WebAssembly/wasi-logging is a Phase 1 WASI proposal. Goals: simple logging for headless programs and as a stderr-style destination for commands. Non-goals: general-purpose async output streams (README).

WIT shape (wit/logging.wit):

  • enum level — trace, debug, info, warn, error, critical
  • log(level, context: string, message: string) — context is an uninterpreted grouping string

Design notes from the README: no LOG_EMERG/LOG_ALERT analogues because guests must not claim visibility into “the system as a whole”; Critical may optionally trap. Levels align with common language log crates.

Who implements it

The host provides the import. Guests do not open files or sockets to log.

wasmCloud: wasi:logging is a built-in host capability (trusted compute base). Components import wasi:logging/logging@0.1.0-draft (or unversioned draft); no deploy-time provider link required (Linking at Runtime; WIT reference). Operator docs: structured logs flow to the host logging pipeline with no per-workload interface keys (Host Interface Configuration). Custom hosts enable wasi-logging via wash-runtime features (Building Custom Hosts; Host Plugins).

Caveat: draft interface versioning has bitten implementers (versioned vs unversioned WIT); pin commits when adopting (wasmCloud issue discussion).

Lesson

Best v1-shaped guest log API for personal-cloud: small surface, Host-owned sink, easy to stamp install id + redact. Unstable draft — Host may re-export as a thin Host WIT if pinning WASI drafts is painful.


wasi:cli stdout / stderr

Spec

WASI 0.2 wasi:cli exposes stdin/stdout/stderr as stream handles (stdio.wit): get-stdout / get-stderr → wasi:io/streams output-stream. Guests write bytes; there is no level or structured field.

Wasmtime embedding

WasiCtxBuilder defaults: stdout and stderr eat all input (discard). Embedders can:

  • inherit_stdout / inherit_stderr — write to the host process streams (fine for CLI demos; poor for multi-tenant)
  • stdout / stderr with custom StdoutStream implementations
  • Virtual pipes such as MemoryOutputPipe to capture bytes per instance

Spin practice

Spin captures application stdout/stderr to .spin/logs by default (--log-dir, empty string disables disk) and can also forward logs into OTel when configured (Observing Applications).

Lesson

Stdout is a compatibility / toolchain path (println, libc), not a substitute for attributed structured logs. A multi-App Host should never inherit process stdio for guest Apps; capture per install or discard, and prefer wasi:logging (or Host WIT) for anything operators read.


Host-side OpenTelemetry (no guest WIT)

Spin

When OTEL_EXPORTER_OTLP_* is set, Spin emits OTel traces, metrics, and logs for the runtime / app to a collector; supports inbound/outbound trace context propagation; still keeps local application logs (Observing Applications). The otel plugin wraps collector + dashboards (spinframework/otel-plugin).

wasmCloud

Host flags such as --enable-observability, --enable-logs, and OTLP endpoint overrides configure host emission of OTel signals (Host Configuration). Separate from guest wasi:logging.

Lesson

Host self-instrumentation (request handling, Dataset access, Scheduled work, worker kill) is orthogonal to App-authored logs. personal-cloud will want both: Host spans for security/ops, App logs for author/debug — with different audiences (Instance admin vs App developer).


wasi:otel (guest → host export)

Spec

WebAssembly/wasi-otel is a Phase 2 proposal. Package example: wasi:otel@0.2.0-rc.2 world imports pulls in types, tracing, metrics, logs (world.wit).

Goals: let components use standard OTel SDKs; closely mirror upstream OTel APIs. Non-goal: a WIT meant for hand-written direct consumption (README).

Design rationale (same README):

  • Guests should not export telemetry over WASI HTTP to a collector — that breaks tying guest spans into host component-graph traces, and short-lived components should buffer to the host instead of opening network.
  • Generic “WASI Observe” deferred; OTel-shaped WIT first.

Implementations

  • Spin 3.6+: experimental WASI OTel; opentelemetry-wasi crate (WasiSpanProcessor, WasiMetricExporter, WasiLogProcessor) forwards SDK signals via WIT; TraceContextPropagator parents guest spans under Spin request spans; run with --experimental-wasi-otel (Announcing Spin v3.6). Blog text still called the proposal Phase 1 at publish time; the proposal README now lists Phase 2 — prefer the proposal repo for phase.
  • wasmCloud / wash-runtime: wasi-otel host feature/plugin; OTLP endpoints from host OTEL_* env; activated with --wasi-otel (Host Interface Configuration; Building Custom Hosts).

Lesson

Right architecture for richer observability later: guest SDK → host import → host policy → optional OTLP. Guests never hold collector credentials. For v1 concept spec, treat as vision / optional; still cite the “export to host, not network” rule as a hard isolation principle even if the WIT is not adopted yet.


Browser client Wasm

Platform facts

Dedicated workers expose console on WorkerGlobalScope; console.log in a dedicated worker appears in that tab’s DevTools console (MDN WorkerGlobalScope.console; Using Web Workers).

Portable Wasm has no ambient Web APIs — only Shell-provided imports (prior research). So client App logging product surface is whatever the Shell imports (e.g. log → postMessage → Shell → Host WebSocket), not whatever happens to hit DevTools.

Lesson

Align client and server: same logical “emit log line” capability, different transport. Do not rely on browser console for Instance admin observability. Shell may still allow DevTools for local App authors without forwarding secrets or Host internals into the worker.


What the Host should mediate vs what Apps must never see

Host mediates Apps must never see / do
Implementing log/OTel WIT imports Ambient access to Host process stdout, Host log files, or other installs’ streams
Stamping App install id, package id, account, request/correlation ids Raw Host filesystem paths, other tenants’ data, Host secrets
Retention, rate limits, level filters, PII redaction policy Direct OTLP/network to collectors (violates wasi-otel design and our capability bar)
Whether Instance admin vs App author can read a stream Host internal tracing of Grant checks / capability denials as guest-readable detail (policy choice — default deny)
Shell bridge for client Wasm logs Unmediated fetch/socket “just to ship telemetry”

Shortlist for grilling (not a decision)

P0-shaped (concept / v1):

  1. Host-implemented leveled logging — prefer wasi:logging-shaped API (or Host WIT twin if draft pinning is painful); capture optional stdout separately as unstructured fallback.
  2. Per-install attribution on every record; no process-stdio inherit for guests.
  3. Client: Shell bridge import only; optional forward to Host; DevTools is author convenience, not the ops pipeline.

P1 / vision:

  1. Host-side OTel for Host + request correlation (Spin/wasmCloud-style env config).
  2. Optional wasi:otel (or successor) when Apps need author spans/metrics — still host-exported only.

Explicit non-picks for now: guest HTTP to collectors; shared stdout pipe across Apps; treating console.log as the security or multi-user audit log.


Side notes for grilling (keep)

These are not research claims — they are prompts and leanings for Decide App logging and observability model and related tickets:

  • Audiences split early: Instance admin (is the household Host healthy / which App is misbehaving?) vs App author (debug my App). Same pipe with different filters may suffice for v1; don’t accidentally build two products.
  • Stdout as second-class reduces toolchain friction (Rust println!) but invites unstructured PII; decide whether stdout is captured at all in production Builds.
  • Rate limits / quotas belong with Decide Host Wasm resource limits and termination — a chatty logger is a resource attack.
  • Correlation with events: inter-App events already have stable ids (Decide inter-App event and notification model); logging should be able to carry the same ids without Apps inventing a parallel scheme.
  • Capability consent: is logging ambient (always on, like wasmCloud builtin) or a declared capability? Ambient is better DX; declared is better for “Apps that must not log Dataset contents” narratives — grill explicitly.
  • Client hang / kill path: Shell worker lifecycle already asks on visible hang; logs from a dying worker need a last-chance flush story or accept loss (Decide Shell management of App client workers).
  • Don’t over-promise APM in the contributor spec — concept + requirements, not Datadog-in-the-box.

Sources