denoland/deno · error · TypeError
ContextManager can not be constructed
Error message
ContextManager can not be constructed
What it means
ContextManager in Deno's OpenTelemetry shim (ext/telemetry/telemetry.ts:629) is a static-only namespace class, like Math or JSON. It exists solely to expose static methods active(), with(), and bind(); its constructor deliberately throws a TypeError because context state lives in an AsyncLocalStorage-backed global (CURRENT), not in instances. Constructing or subclassing it is unsupported.
Source
Thrown at ext/telemetry/telemetry.ts:651
const c = new Context(this.#data);
c.#data[key] = value;
return c;
}
deleteValue(key: symbol): Context {
const c = new Context(this.#data);
delete c.#data[key];
return c;
}
}
// TODO(lucacasonato): @opentelemetry/api defines it's own ROOT_CONTEXT
const ROOT_CONTEXT = new Context();
// Context manager for opentelemetry js library
class ContextManager {
constructor() {
throw new TypeError("ContextManager can not be constructed");
}
static active(): Context {
return CURRENT.get() ?? ROOT_CONTEXT;
}
static with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(
context: Context,
fn: F,
thisArg?: ThisParameterType<F>,
...args: A
): ReturnType<F> {
const ctx = CURRENT.enter(context);
try {
return ReflectApply(fn, thisArg, args);
} finally {
setAsyncContext(ctx);
}View on GitHub (pinned to a961cdec3b)
Solutions
- Use the static API: ContextManager.active() and ContextManager.with(context, fn, thisArg, ...args)
- Remove the new expression entirely; there is no per-instance state to construct
- If you genuinely need a custom context manager, depend on the real @opentelemetry/api + SDK npm packages instead of Deno's built-in shim
Example fix
// before const cm = new ContextManager(); const ctx = cm.active(); // after const ctx = ContextManager.active();
Defensive patterns
Strategy: validation
Try / catch
try {
// code that may construct ContextManager
} catch (e) {
if (e instanceof TypeError && e.message.includes("can not be constructed")) {
// switch to the static API: ContextManager.active() / .with()
} else {
throw e;
}
} Prevention
- Treat ContextManager as a namespace object (like Math); never use new on it
- Keep custom context-manager code against the real @opentelemetry/api npm packages, not Deno's shim
- Grep migrations for 'new ContextManager' before switching to Deno's built-in otel support
When it happens
Trigger: new ContextManager(); Reflect.construct(ContextManager, []); subclassing via class MyCM extends ContextManager { constructor() { super(); } } while porting an OTel SDK tutorial that installs a custom context manager.
Common situations: Following OpenTelemetry JS docs for the SDK, where ContextManager is an abstract class you extend and register with the SDK's node async-hooks propagation; copy-pasted instrumentation setup code assuming the SDK API surface; code migrating from @opentelemetry/api's experimental context-propagation packages.
Related errors
- MeterProvider can not be constructed
- startActiveSpan requires a function argument
- Only valueType: DOUBLE is supported
- vsock is not supported on this platform
- invalid vsock addr
AI-assisted analysis of denoland/deno@a961cdec3b (2026-08-20).
Data as JSON: /api/errors/360b11ec46460b44.
Report an issue: GitHub.