function bitrot()

in scripts/bitrot.js [132:217]


function bitrot() {
    const pj = JSON.parse(fs.readFileSync(ETEL_PJ_PATH, 'utf8'));
    const instrNames = Object.keys(pj.dependencies).filter((d) =>
        d.startsWith('@opentelemetry/instrumentation-')
    );

    const ainPj = getNpmInfo('@opentelemetry/auto-instrumentations-node');
    const ainInstrNames = Object.keys(ainPj.dependencies).filter((d) =>
        d.startsWith('@opentelemetry/instrumentation-')
    );

    for (let instrName of ainInstrNames) {
        if (SKIP_INSTR_NAMES.includes(instrName)) continue;
        if (!instrNames.includes(instrName)) {
            rot(instrName, 'missing instr that auto-instrumentations-node has');
        }
    }

    for (let instrName of instrNames) {
        if (SKIP_INSTR_NAMES.includes(instrName)) continue;

        if (!QUIET) console.log(`${instrName}:`);
        const mod = require(instrName);
        const instrClass = Object.keys(mod).filter((n) =>
            n.endsWith('Instrumentation')
        )[0];
        const instr = new mod[instrClass]();
        const initVal = instr.init(); // grpc is weird here
        if (initVal === undefined) {
            if (!QUIET) console.log(`    (instr.init() returned undefined!)`);
            continue;
        }
        const instrNodeModuleFiles = Array.isArray(initVal)
            ? initVal
            : [initVal];

        const supVersFromModName = {};
        for (let inmf of instrNodeModuleFiles) {
            // TODO: warn if supportedVersions range is open-ended. E.g. if it satisfies 9999.9999.9999 or something.
            if (!QUIET)
                console.log(
                    `    ${inmf.name}: ${JSON.stringify(
                        inmf.supportedVersions
                    )}`
                );
            // TODO: keep printing these? Do they ever matter?
            for (let file of inmf.files) {
                if (!QUIET)
                    console.log(
                        `        ${file.name}: ${JSON.stringify(
                            file.supportedVersions
                        )}`
                    );
            }
            if (!supVersFromModName[inmf.name]) {
                supVersFromModName[inmf.name] = [];
            }
            supVersFromModName[inmf.name].push(inmf.supportedVersions);
        }
        for (let modName of Object.keys(supVersFromModName)) {
            const supVers = supVersFromModName[modName].flat();
            if (supVers.toString() === '*') {
                // This is code for "node core module".
                continue;
            }
            const info = getNpmInfo(modName);
            const latest = info['dist-tags'].latest;
            if (!QUIET)
                console.log(`    latest published: ${modName}@${latest}`);
            let supsLatest = false;
            for (let range of supVers) {
                if (semver.satisfies(latest, range)) {
                    supsLatest = true;
                }
            }
            if (!supsLatest) {
                rot(
                    instrName,
                    `supportedVersions of module "${modName}" (${JSON.stringify(
                        supVers
                    )}) do not support the latest published ${modName}@${latest}`
                );
            }
        }
    }
}