{"record":{"id":"b50edc6778357ef6","repo":"denoland/deno","slug":"meterprovider-can-not-be-constructed","errorCode":null,"errorMessage":"MeterProvider can not be constructed","messagePattern":"MeterProvider can not be constructed","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/telemetry/telemetry.ts","lineNumber":759,"sourceCode":"    name: string,\n    description?: string,\n    unit?: string,\n  ): Instrument;\n  createObservableUpDownCounter(\n    name: string,\n    description?: string,\n    unit?: string,\n  ): Instrument;\n  createObservableGauge(\n    name: string,\n    description?: string,\n    unit?: string,\n  ): Instrument;\n}\n\nclass MeterProvider {\n  constructor() {\n    throw new TypeError(\"MeterProvider can not be constructed\");\n  }\n\n  static getMeter(\n    name: string,\n    version?: string,\n    options?: MeterOptions,\n  ): Meter {\n    const meter = new OtelMeter(name, version, options?.schemaUrl);\n    return new Meter(meter);\n  }\n}\n\ntype MetricAttributes = Attributes;\n\ntype Instrument = { __key: \"instrument\" };\n\nlet batchResultHasObservables: (\n  res: BatchObservableResult,","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/telemetry/telemetry.ts#L741-L777","documentation":"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.","triggerScenarios":"const provider = new MeterProvider(); const meter = provider.getMeter('lib'); copying SDK-based examples that instantiate a provider, register a reader, and call provider.shutdown().","commonSituations":"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.","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"],"exampleFix":"// before\nconst provider = new MeterProvider();\nconst meter = provider.getMeter('app');\n\n// after\nconst meter = MeterProvider.getMeter('app');","handlingStrategy":"validation","validationCode":"// No construction exists to validate; use the static factory directly\nconst meter = MeterProvider.getMeter(\"my-lib\", \"1.0.0\");","typeGuard":null,"tryCatchPattern":"try {\n  // code that may construct MeterProvider\n} catch (e) {\n  if (e instanceof TypeError && e.message.includes(\"can not be constructed\")) {\n    // replace with MeterProvider.getMeter(name)\n  } else {\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["opentelemetry","metrics","telemetry","static-class","api-misuse"],"backgroundTag":"static-class-instantiation","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}