-
Notifications
You must be signed in to change notification settings - Fork 948
Description
We recently exported a const enum: export const enum SemconvStability from #5684, released in @opentelemetry/[email protected]. From a quick look, there are no other const enum exports from packages in this repo.
TIL exporting a const enum from a package is problematic for some usages of the package. https://ncjamieson.com/dont-export-const-enums/ explains the issue. Some tooling will compile TS modules one file at a time in isolation. In those cases, a const enum reference, e.g. SemconvStability.OLD, cannot be resolved. One such tooling example is ts-node being used by mocha for testing in opentelemetry-js.git and opentelemetry-js-contrib.git. I gather that this was not an issue for usage of SemconvStability in the same repo (e.g. in instr-http, instr-xhr, instr-fetch), because it is a monorepo where the dependencies are symlinks to the source dir.
We hit the error in this PR, the first one in opentelemetry-js-contrib to attempt to use SemconvStability: open-telemetry/opentelemetry-js-contrib#2671 (comment)
To fix this:
- Change the SemconvStabilty from
const enumtoenum. I've confirmed this fixes the testing issue for the instrumentation-knex PR above. fix(instrumentation): changeSemconvStabilityexport fromconst enumtoenum#5692 - Do a patch release to fix this. (Marc did a v0.201.1 release in chore: prepare next release #5696)
- Discuss whether we want to add
isolatedModules: trueto our tsconfig.json in the opentelemetry-js repo. This config is suggested in the blog post above as a way to guard against exporting const enums. Adding this config also means dealing with a number (153) of cases oferror TS1205: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.in our packages, so this is a larger change. (See chore: enable tsconfig isolatedModules #5697) - See chore: set
isolatedModulescompilation option opentelemetry-js-contrib#2839 for contrib repo