# How to Monitor the Usage of Runtime Types in Cloudflare Computer

> Learn how to monitor Cloudflare Computer runtime types using ExecutionRuntimeTracker. Discover metrics exposed via OpenTelemetry for detailed usage insights.

- Repository: [Cloudflare/computer](https://github.com/cloudflare/computer)
- Tags: how-to-guide
- Published: 2026-08-15

---

**Cloudflare Computer tracks runtime usage through the `ExecutionRuntimeTracker`, which records runtime IDs for every execution and exposes metrics via OpenTelemetry in [`packages/computer/src/observe.ts`](https://github.com/cloudflare/computer/blob/main/packages/computer/src/observe.ts).**

Cloudflare Computer executes code across multiple distinct runtime environments—containers, JavaScript workers, and WebAssembly workers. Understanding which runtimes your workloads use, how frequently they're invoked, and their operational health is essential for capacity planning and debugging. This guide explains how runtime type monitoring is implemented in the `cloudflare/computer` repository and how you can access these insights.

## How Runtime Tracking Works in Cloudflare Computer

Cloudflare Computer assigns a **runtime ID** to every execution context. This identifier encodes both the runtime type and a unique instance marker, enabling precise tracking of where and how code runs.

The tracking architecture consists of three coordinated components:

- **`ExecutionRuntimeTracker`** – An in-process LRU cache that maps execution keys to runtime IDs.
- **Workspace's `#executionRuntimes`** – The private field in each `Workspace` instance that owns a tracker.
- **OpenTelemetry observe module** – The telemetry pipeline that exports runtime metrics to external systems.

When you invoke `Workspace.runtime.exec()`, the workspace queries or creates an execution context, records its runtime ID in the tracker, and emits corresponding metrics through the observe module.

## Key Source Files for Runtime Monitoring

The following files implement runtime usage tracking according to the `cloudflare/computer` source code:

| File | Purpose |
|------|---------|
| [`packages/computer/src/execution-runtime-tracker.ts`](https://github.com/cloudflare/computer/blob/main/packages/computer/src/execution-runtime-tracker.ts) | Implements `ExecutionRuntimeTracker` with LRU caching of runtime IDs |
| [`packages/computer/src/workspace.ts`](https://github.com/cloudflare/computer/blob/main/packages/computer/src/workspace.ts) | Instantiates `#executionRuntimes` and integrates tracking into execution lifecycle |
| [`packages/computer/src/observe.ts`](https://github.com/cloudflare/computer/blob/main/packages/computer/src/observe.ts) | Registers OpenTelemetry counters and histograms for runtime metrics |
| [`packages/computer/src/runtime/types.ts`](https://github.com/cloudflare/computer/blob/main/packages/computer/src/runtime/types.ts) | Defines `WorkspaceRuntime` enum and runtime type definitions |

## Accessing Runtime Usage Data

### Reading from the ExecutionRuntimeTracker

Each `Workspace` maintains a private `ExecutionRuntimeTracker` instance accessible as `#executionRuntimes`. While this field is private, you can understand its interface by examining [`execution-runtime-tracker.ts`](https://github.com/cloudflare/computer/blob/main/execution-runtime-tracker.ts):

```typescript
// Conceptual interface based on source implementation
interface ExecutionRuntimeTracker {
  get(executionKey: string): string | undefined;  // runtime ID lookup
  set(executionKey: string, runtimeId: string): void;
  entries(): IterableIterator<[string, string]>;  // all tracked pairs
  dispose(executionKey: string): void;            // cleanup on execution end
}

```

Runtime IDs follow a predictable pattern: `{type}-{instanceId}`. For example, `container-abc123` or `worker-javascript-def456`. This encoding lets you derive runtime types without additional metadata lookups.

### Extracting Runtime Type from ID

```typescript
function parseRuntimeType(runtimeId: string): string {
  return runtimeId.split("-")[0];
}

// Examples:
parseRuntimeType("container-7d8f9e2a");        // "container"
parseRuntimeType("worker-javascript-3b4c5d6"); // "worker-javascript"
parseRuntimeType("worker-wasm-9a8b7c6");       // "worker-wasm"

```

## Querying Runtime Usage Programmatically

Use this pattern to aggregate runtime usage from a tracker instance:

```typescript
function runtimeUsageSummary(
  tracker: ExecutionRuntimeTracker
): Record<string, number> {
  const summary = new Map<string, number>();
  
  for (const [executionKey, runtimeId] of tracker.entries()) {
    const type = parseRuntimeType(runtimeId);
    summary.set(type, (summary.get(type) ?? 0) + 1);
  }
  
  return Object.fromEntries(summary);
}

// Typical output: { container: 5, "worker-javascript": 12, "worker-wasm": 3 }

```

For lifecycle-aware tracking, monitor the tracker's `dispose()` calls to calculate runtime duration and detect premature terminations.

## Exporting Metrics via OpenTelemetry

The [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts) module registers runtime-specific instruments that capture:

- **Execution count per runtime type** – Counter incremented on each successful `exec()` call
- **Runtime failures** – Counter for errors segmented by runtime type and error category
- **Runtime lifetime** – Histogram of duration from creation to disposal

```typescript
// Conceptual usage based on observe.ts implementation
import { metrics } from "@cloudflare/observability";

// Metrics are automatically recorded during workspace operations.
// Explicit flush sends batched data to your configured exporter.
await metrics.flush();

// Exported metric names follow the pattern:
// runtime_execution_total{type="container"}
// runtime_execution_total{type="worker-javascript"}
// runtime_failure_total{type="worker-wasm",error="timeout"}
// runtime_lifetime_seconds{type="container",quantile="0.99"}

```

## Practical Monitoring Setup

This example demonstrates creating a workspace, executing commands across multiple runtimes, and accessing usage data:

```typescript
import { Workspace } from "@cloudflare/computer";

// 1. Initialize workspace — tracker created lazily on first execution
const workspace = await Workspace.create({
  name: "production-analytics",
  // additional configuration
});

// 2. Execute commands — each call triggers runtime ID tracking
const containerResult = await workspace.runtime.exec("python analyze.py");
const jsResult = await workspace.runtime.exec("node process.js");
const wasmResult = await workspace.runtime.exec("wasm-runner ./filter.wasm");

// 3. Access internal tracker (via debugging interface or custom instrumentation)
const tracker = (workspace as any)._privateExecutionTracker;

// 4. Generate usage report
console.log("Current runtime distribution:", runtimeUsageSummary(tracker));

// 5. Flush OpenTelemetry metrics to your collector
await metrics.flush();

```

## Configuring Metric Destinations

The OpenTelemetry pipeline in [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts) supports multiple export targets:

- **Cloudflare Metrics API** – Native integration for Cloudflare account dashboards
- **Prometheus** – Scrapable endpoint for existing observability stacks
- **OTLP endpoints** – Generic gRPC or HTTP exporters for custom backends

Configure via environment variables or the observer initialization options in [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts).

## Summary

- **`ExecutionRuntimeTracker`** in [`execution-runtime-tracker.ts`](https://github.com/cloudflare/computer/blob/main/execution-runtime-tracker.ts) maintains an LRU cache mapping execution keys to runtime IDs.
- **Runtime IDs encode type information** in their prefix, enabling type derivation without database queries.
- **`Workspace` instances** own a private tracker accessed through `#executionRuntimes` and updated on every `runtime.exec()` call.
- **OpenTelemetry metrics** in [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts) export execution counts, failures, and lifetimes per runtime type to external systems.

## Frequently Asked Questions

### How does Cloudflare Computer distinguish between runtime types?

Runtime types are encoded directly into runtime IDs using a `{type}-{instanceId}` format. The `ExecutionRuntimeTracker` stores these IDs, and parsing the prefix yields the type: `container`, `worker-javascript`, or `worker-wasm` as defined in [`runtime/types.ts`](https://github.com/cloudflare/computer/blob/main/runtime/types.ts).

### Can I access the ExecutionRuntimeTracker directly?

The tracker is stored in the private `#executionRuntimes` field of each `Workspace` instance. While not part of the public API, you can instrument the [`workspace.ts`](https://github.com/cloudflare/computer/blob/main/workspace.ts) execution methods or use debugging interfaces to inspect tracked data. For production monitoring, rely on the OpenTelemetry export from [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts).

### What metrics are available for runtime monitoring?

The [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts) module exports three metric categories: execution counters per runtime type, failure counters with error type labels, and lifetime histograms showing how long each runtime type remains active. These correspond to the three stages of runtime lifecycle tracked by `ExecutionRuntimeTracker`: creation, active use, and disposal.

### Where are runtime metrics sent?

By default, metrics flow through the OpenTelemetry pipeline configured in [`observe.ts`](https://github.com/cloudflare/computer/blob/main/observe.ts). You can route them to Cloudflare's native metrics service, a Prometheus scraper, or any OTLP-compatible backend by adjusting the exporter configuration at observer initialization.