datarobot_genai.drtools.core.sandbox.observability
observability
Observability for sandboxed code execution.
Defines the SLI building blocks: a pure :func:classify_outcome that turns an
execution result/error into an (outcome, reason) pair, plus (later in this
module) the OTel instruments and the :class:InstrumentedSandbox wrapper.
:func:classify_outcome stays a pure function of the execution error so the
failure taxonomy is unit-testable without touching any OTel state.
SandboxInstruments
dataclass
The three OTel instruments backing the sandbox SLIs.
Held together so they can be dependency-injected (tests bind them to an in-memory reader) or lazily built from the global meter in production.
Source code in datarobot_genai/drtools/core/sandbox/observability.py
InstrumentedSandbox
Wraps any :class:~datarobot_genai.drtools.core.sandbox.base.Sandbox backend
and records SLI metrics + a span around each execution.
Because it composes the Sandbox Protocol rather than subclassing a
concrete backend, the same instrumentation covers LocalDockerSandbox,
DataRobotWorkloadSandbox, and any future backend — define the SLIs once.
Source code in datarobot_genai/drtools/core/sandbox/observability.py
classify_outcome
Classify an execution into (outcome, reason) for the SLIs.
Parameters
error
The exception raised by the sandbox, or None if the execution
returned a :class:~datarobot_genai.drtools.core.sandbox.base.SandboxResult.
Returns
tuple[str, str | None]
("success", None) on success, otherwise ("failure", reason)
where reason is one of "timeout", "oom", "infra", or
"crash".
Source code in datarobot_genai/drtools/core/sandbox/observability.py
build_instruments
Create the sandbox instruments on meter (an OTel Meter).
Source code in datarobot_genai/drtools/core/sandbox/observability.py
get_instruments
Build (and cache) instruments from the global meter.
Instruments are cached, but keyed on the active global MeterProvider: if
the provider changes (e.g. a no-op/proxy provider was current on first use
and bootstrap_metrics_provider later installs the real SDK provider), the
instruments are rebuilt against the new provider rather than staying pinned
to the old one. Without a bootstrapped provider the instruments record into
OTel's no-op provider, so callers never need to guard.
Source code in datarobot_genai/drtools/core/sandbox/observability.py
record_execution
record_execution(outcome: str, reason: str | None, duration_s: float, *, instruments: SandboxInstruments | None = None) -> None
Emit the SLI metrics for one execution.