denoland/deno · error · TypeError
MeterProvider can not be constructed
Error message
MeterProvider can not be constructed
What it means
MeterProvider in Deno's OpenTelemetry metrics shim (ext/telemetry/telemetry.ts:737) is a static-only class. It exists solely for the static factory MeterProvider.getMeter(name, version?, options?) which returns a Meter; the constructor throws TypeError because meters are obtained through the factory, never via new. This differs from @opentelemetry/sdk-metrics, where new MeterProvider() is the normal entry point.
Source
Thrown at ext/telemetry/telemetry.ts:759
name: string,
description?: string,
unit?: string,
): Instrument;
createObservableUpDownCounter(
name: string,
description?: string,
unit?: string,
): Instrument;
createObservableGauge(
name: string,
description?: string,
unit?: string,
): Instrument;
}
class MeterProvider {
constructor() {
throw new TypeError("MeterProvider can not be constructed");
}
static getMeter(
name: string,
version?: string,
options?: MeterOptions,
): Meter {
const meter = new OtelMeter(name, version, options?.schemaUrl);
return new Meter(meter);
}
}
type MetricAttributes = Attributes;
type Instrument = { __key: "instrument" };
let batchResultHasObservables: (
res: BatchObservableResult,View on GitHub (pinned to a961cdec3b)
Solutions
- Use the static factory: MeterProvider.getMeter('my-lib', '1.0.0')
- Delete SDK lifecycle code (addReader, forceFlush, shutdown) when running against Deno's shim; the exporter is configured by Deno's runtime flags, not by the provider
- Check which import specifier your module resolves @opentelemetry/api from; Deno redirects it to the internal shim only in the expected configuration
Example fix
// before
const provider = new MeterProvider();
const meter = provider.getMeter('app');
// after
const meter = MeterProvider.getMeter('app'); Defensive patterns
Strategy: validation
Validate before calling
// No construction exists to validate; use the static factory directly
const meter = MeterProvider.getMeter("my-lib", "1.0.0"); Try / catch
try {
// code that may construct MeterProvider
} catch (e) {
if (e instanceof TypeError && e.message.includes("can not be constructed")) {
// replace with MeterProvider.getMeter(name)
} else {
throw e;
}
} Prevention
- Replace SDK provider bootstrap with the static getMeter call when adopting Deno's otel shim
- Delete addReader/shutdown lifecycle code; Deno configures export via runtime flags
- Search for 'new MeterProvider' when porting opentelemetry-js examples
When it happens
Trigger: const provider = new MeterProvider(); const meter = provider.getMeter('lib'); copying SDK-based examples that instantiate a provider, register a reader, and call provider.shutdown().
Common situations: Migrating an app from the OpenTelemetry JS SDK to Deno's built-in otel support (DENO_OTEL_OTLP_ENDPOINT / --unstable-otel) without adjusting provider bootstrap code; tutorials copy-pasted from opentelemetry-js docs.
Related errors
- ContextManager can not be constructed
- Only valueType: DOUBLE is supported
- startActiveSpan requires a function argument
- Counter can only be incremented
- Observable counters can only be incremented
AI-assisted analysis of denoland/deno@a961cdec3b (2026-08-20).
Data as JSON: /api/errors/b50edc6778357ef6.
Report an issue: GitHub.