Traces
The engine's OpenTelemetry spans — what a create, a pause or a fork waits for, and what goes on after the answer — and how a host collects them.
The engine (@spunto/sandbox/engine) is instrumented against @opentelemetry/api only, as a
library should be: it never loads an SDK nor exports anything itself. Without an SDK registered by
the process that runs it, every span is the API's no-op — nothing recorded, nothing changes. This is
the case of spunto-sandboxd and sbx as they ship.
Two kinds of traces
An operation answers within a few seconds and leaves the slow part running (an image to unpack, a RAM to write). So there are two traces:
- What the caller waits for:
engine.<op>, a child of the span active when the operation is called (the host's request), with its steps under it. - What goes on after the answer: a trace of its own,
sandbox.<what>, a root (kind: CONSUMER, no parent) with a span link to theengine.<op>span that started it. Its trace id is given back in the operation's answer asasyncTraceId, and set onengine.<op>asasync.trace_id(andasync.span_id, the root's span id).
trace of the request trace of the boot (its own)
node.create (the host's) sandbox.boot ── link: triggered_by → engine.create
└─ engine.create async.trace_id=… ├─ engine.source
├─ engine.ensure_host ├─ image.ensure ─ image.resolve, image.unpack
├─ engine.pool_room ─ zfs get ├─ zfs clone, zfs set …
├─ engine.memory_room ─ systemctl show └─ vmm.boot
└─ registry.save ├─ vmm.spawn ─ network.ensure, jail.make, systemd-run
└─ firecracker PUT /boot-source … PUT /actionsasyncTraceId is absent when there is nothing after the answer, when no SDK is loaded (the no-op's
trace id is invalid) or when the root was not sampled.
Operations
| Operation | Span of the call | After the answer |
|---|---|---|
create | engine.create | sandbox.boot |
start | engine.start (sandbox.start.how: RAM loaded, booted from disk…) | — |
stop | engine.stop | sandbox.stop |
pause | engine.pause | sandbox.pause |
fork | engine.fork (the source's pause, vmm.freeze) | sandbox.fork (the copy's memory) |
snapshot | engine.snapshot (the source's pause) | sandbox.snapshot |
snapshotDisks | engine.snapshot_disks (all of it) | — |
build | engine.build | sandbox.build (a new build only) |
exportBuild | engine.export_build | sandbox.export_build |
destroy | engine.destroy (engine.destroy.pending when it outlives its 6 s) | — |
grow, archive, restore, deleteBuild, deleteTemplate | engine.<op> | — |
describe, list, templateStatus, buildStatus, exportStatus, sizes and usage make no
span: a platform polls them every 100 ms. The engine's own waits are one span each, never one per look. Nor do the engine's own sweeps (timers), nor what a
restart of the daemon takes up (a stop or a build left halfway).
Steps
Under an operation or a background root, and nowhere else:
| Span | What |
|---|---|
engine.ensure_host | the host's setup (host.setup: true on the call that did it), a wait for it otherwise |
engine.pool_room, engine.memory_room | the room checks (zfs.pool.free_bytes; sandbox.size) |
engine.source | what a box starts from (sandbox.from): waits for a fork's memory |
image.ensure, image.resolve, image.unpack | the image's disk (image.id, image.cached, image.shared: another box's unpack waited for), its digest, the pull and extraction in a throwaway microVM |
vmm.boot, vmm.load, vmm.spawn, vmm.stop | a cold boot, a RAM loaded, the VMM's unit, its end |
network.ensure, network.remove | the box's netns, tap, veth, rules, shaping |
jail.make | the jailer's chroot |
vmm.freeze, vmm.save_ram, vmm.clean_shutdown | a pause for a copy, a RAM written, a guest shut down |
vmm.wait_exit | a wait for a VMM to end (a guest powering off, an unpacker, a recipe): one span, not one per look at its unit |
memory.prepare_base, memory.merge | the memory file a Diff goes over, the Diff merged into it (vmm.ram_kind) |
build.fetch, build.recipe | a build fetched from a bucket, the recipe running in its builder |
archive.send, archive.receive | a box's disks to a bucket and back |
registry.save | the registry written |
<tool> <subcommand> | every host command: zfs clone, systemctl show, ip netns, bash… (process.command_args for zfs, systemctl, ip, tc, iptables and the like — never a script's text nor a URL) |
firecracker <METHOD> <path> | a call to a VMM's API: firecracker PUT /snapshot/create |
A sandbox.boot has an event per step describe shows (creating disks, booting…, attribute
sandbox.step), and sandbox.source (image, build, template:fork…).
Attributes and errors
sandbox.id,sandbox.handle,sandbox.image,sandbox.size,sandbox.from,sandbox.template.ref,sandbox.template.kind,sandbox.build.id,sandbox.build.ref.- A background root ends with
async.outcome—running(a boot),paused,stopped(a pause whose RAM could not be kept saysstopped, and why inasync.detail),ready(a fork, a snapshot, a build, an export),error,missing(destroyed or deleted meanwhile) — andasync.detail. - An error: status
ERRORwith its message, the exception recorded, anderror.type: theSandboxErrorcode (not_found,invalid,capacity,upstream). A host command that fails is not an error of its own span (many are probes:zfs listof what is not there) — onlyerror.typeon it; the step that gave up on it carries the error. - The link from a root:
spunto.link = "triggered_by". - The tracer:
@spunto/sandbox, the package's version.
Collecting them
The host registers an SDK — a context manager (AsyncLocalStorage) for the steps to find their
parent, and a tracer provider — then calls the engine inside its own span:
import { context, trace } from "@opentelemetry/api"
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks"
import { BatchSpanProcessor, BasicTracerProvider } from "@opentelemetry/sdk-trace-base"
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
import { engine } from "@spunto/sandbox/engine"
context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable())
trace.setGlobalTracerProvider(new BasicTracerProvider({ spanProcessors: [new BatchSpanProcessor(new OTLPTraceExporter())] }))
// (or @opentelemetry/sdk-node's NodeSDK, which does both)
const made = await trace.getTracer("my-host").startActiveSpan("node.create", async (span) => {
try {
const r = await engine.create({ sandboxId, name, image, bootstrap, env })
if (r.asyncTraceId) span.setAttribute("async.trace_id", r.asyncTraceId)
return r
} finally {
span.end()
}
})The engine imports @opentelemetry/api (a dependency, ^1.3.0) rather than carrying a copy, so
that npm gives the host's SDK and the engine the same one: the API's global registry is shared only
between copies of compatible versions. A host that bundles the engine (esbuild) bundles that one
copy.
A fork or a snapshot answers once its source runs again, or after 7 s whatever happens (a Full of a large box): the trace of its memory begins as the source runs again — after an answer given at 7 s, it is there all the same, linked, but its id was not in the answer.