Registry / observability / opentelemetry-node-bundler-plugin-utils

opentelemetry-node-bundler-plugin-utils

JSON →
library0.7.0jsnpmunverified

The `opentelemetry-node-bundler-plugin-utils` package provides a set of internal utilities specifically designed for developing OpenTelemetry bundler plugins. It is *not* intended for direct use by application developers, but rather as a dependency for other packages within the OpenTelemetry bundler plugin ecosystem. This library helps plugin authors with tasks like identifying installed OpenTelemetry instrumentations, parsing `package.json` dependencies, and creating `require` functions for specific contexts. Currently at version 0.7.0, its API should be considered unstable and subject to change before a 1.0.0 release. It forms a crucial foundational layer for other OpenTelemetry bundler plugins to achieve their instrumentation goals, offering shared logic to reduce duplication and ensure consistency across different plugin implementations.

npm install opentelemetry-node-bundler-plugin-utils
INSTALL
IMPORT
SIG · OPENTELEMETRY-NODE
O
opentelemetry-node-bundler-plugin-utils
observabilityjavascriptv0.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getOpenTelemetryInstrumentationList
import { getOpenTelemetryInstrumentationList } from '@opentelemetry/node-bundler-plugin-utils';
const { getOpenTelemetryInstrumentationList } = require('@opentelemetry/node-bundler-plugin-utils');
Primarily an internal utility for bundler plugin development. The package ships with TypeScript types.
getPackageJsonDependencies
import { getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';
import getPackageJsonDependencies from '@opentelemetry/node-bundler-plugin-utils';
Exports are typically named. Avoid default import as it is not provided.
createRequire
import { createRequire } from '@opentelemetry/node-bundler-plugin-utils';
const createRequire = require('@opentelemetry/node-bundler-plugin-utils').createRequire;
Used by bundler plugins to create a `require` function relative to a specific path, often for dynamic module loading. Intended for internal plugin logic.

Demonstrates how a hypothetical OpenTelemetry bundler plugin might use `getOpenTelemetryInstrumentationList` and `getPackageJsonDependencies` to analyze a project's dependencies and identify relevant OpenTelemetry instrumentations for bundling.

import { getOpenTelemetryInstrumentationList, getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils'; import * as path from 'path'; import * as fs from 'fs'; interface PackageJson {dependencies?: Record<string, string>; devDependencies?: Record<string, string>;} async function simulateBundlerPluginLogic(projectRoot: string) { const packageJsonPath = path.join(projectRoot, 'package.json'); if (!fs.existsSync(packageJsonPath)) { console.error(`Error: package.json not found at ${packageJsonPath}`); return; } const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8'); const packageJson: PackageJson = JSON.parse(packageJsonContent); // Example 1: Get all dependencies from package.json const allDependencies = getPackageJsonDependencies(packageJson); console.log('Detected dependencies:', Object.keys(allDependencies)); // Example 2: Identify installed OpenTelemetry instrumentations // In a real scenario, this might involve more sophisticated path resolution const instrumentations = await getOpenTelemetryInstrumentationList(projectRoot); console.log('Detected OpenTelemetry Instrumentations:', instrumentations); if (instrumentations.length > 0) { console.log(` Bundler plugin would now configure/apply transformations for the following instrumentations: - ${instrumentations.join('\n - ')} `); } else { console.log('\nNo OpenTelemetry instrumentations detected for bundling.'); } } // To run this, create a dummy package.json in a 'test-project' directory // e.g., test-project/package.json with {"dependencies": {"@opentelemetry/instrumentation-http": "^0.30.0"}} // and run 'npm install' inside test-project. // Then execute this script, pointing to the test-project root. // For demonstration, we'll use current directory assuming it's a test project: simulateBundlerPluginLogic(process.cwd()).catch(console.error);
Debug
Known issues
gotchaThis package is explicitly designed as an internal utility for other OpenTelemetry bundler plugins and is not intended for direct use by application developers. Directly depending on it may lead to unexpected behavior or breaking changes without warning.
fix
Avoid direct consumption of this package. Instead, use official OpenTelemetry instrumentation libraries or bundler plugins that internally utilize this utility.
affects: >=0.1.0
breakingAs a pre-1.0.0 package (current version 0.7.0), the API is considered unstable. Minor versions may introduce breaking changes, and there are no guarantees of backward compatibility.
fix
If you are a plugin developer using this directly (against advice), pin exact versions to avoid unexpected breakage. Regularly review the changelog for updates, especially before upgrading to new minor versions.
affects: >=0.1.0
gotchaPath resolution for utilities like `getOpenTelemetryInstrumentationList` relies on the provided `projectRoot`. Incorrectly specifying this path can lead to instrumentations not being detected or incorrect module resolution, especially in monorepos or complex build setups.
fix
Ensure the `projectRoot` argument passed to utility functions accurately reflects the root directory of the application being bundled or analyzed. Test thoroughly in your specific build environment.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module '@opentelemetry/node-bundler-plugin-utils'
The package is not installed or the import path is incorrect.
fix
Run `npm install @opentelemetry/node-bundler-plugin-utils` or `yarn add @opentelemetry/node-bundler-plugin-utils`. Verify the import path is exactly as specified in documentation or package exports.
TypeError: Cannot read properties of undefined (reading 'getPackageJsonDependencies')
Attempting to use a named export via a default import, or destructuring from an undefined import.
fix
Ensure you are using named imports for functions like `getPackageJsonDependencies`: `import { getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';`
TS2305: Module '"@opentelemetry/node-bundler-plugin-utils"' has no exported member 'SomeNonExistentExport'.
Trying to import a symbol that does not exist or has been removed from the package's public API.
fix
Consult the package's source code or documentation (if available) to verify the correct names of exported symbols. Remember this is an internal utility, and its exports are not guaranteed to be stable or documented for public use.
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
opentelemetry-node-bundler-plugin-utils — npm install opentelemetry-node-bundler-plugin-utils · libregistry