Skip to Content
Spunto Sandbox

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 the engine.<op> span that started it. Its trace id is given back in the operation's answer as asyncTraceId, and set on engine.<op> as async.trace_id (and async.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 /actions

asyncTraceId 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

OperationSpan of the callAfter the answer
createengine.createsandbox.boot
startengine.start (sandbox.start.how: RAM loaded, booted from disk…)—
stopengine.stopsandbox.stop
pauseengine.pausesandbox.pause
forkengine.fork (the source's pause, vmm.freeze)sandbox.fork (the copy's memory)
snapshotengine.snapshot (the source's pause)sandbox.snapshot
snapshotDisksengine.snapshot_disks (all of it)—
buildengine.buildsandbox.build (a new build only)
exportBuildengine.export_buildsandbox.export_build
destroyengine.destroy (engine.destroy.pending when it outlives its 6 s)—
grow, archive, restore, deleteBuild, deleteTemplateengine.<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:

SpanWhat
engine.ensure_hostthe host's setup (host.setup: true on the call that did it), a wait for it otherwise
engine.pool_room, engine.memory_roomthe room checks (zfs.pool.free_bytes; sandbox.size)
engine.sourcewhat a box starts from (sandbox.from): waits for a fork's memory
image.ensure, image.resolve, image.unpackthe 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.stopa cold boot, a RAM loaded, the VMM's unit, its end
network.ensure, network.removethe box's netns, tap, veth, rules, shaping
jail.makethe jailer's chroot
vmm.freeze, vmm.save_ram, vmm.clean_shutdowna pause for a copy, a RAM written, a guest shut down
vmm.wait_exita 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.mergethe memory file a Diff goes over, the Diff merged into it (vmm.ram_kind)
build.fetch, build.recipea build fetched from a bucket, the recipe running in its builder
archive.send, archive.receivea box's disks to a bucket and back
registry.savethe 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 says stopped, and why in async.detail), ready (a fork, a snapshot, a build, an export), error, missing (destroyed or deleted meanwhile) — and async.detail.
  • An error: status ERROR with its message, the exception recorded, and error.type: the SandboxError code (not_found, invalid, capacity, upstream). A host command that fails is not an error of its own span (many are probes: zfs list of what is not there) — only error.type on 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.

On this page