{"id":13717,"library":"opentelemetry-node-bundler-plugin-utils","title":"OpenTelemetry Bundler Plugin Utilities","description":"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.","status":"active","version":"0.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/DrewCorlin/opentelemetry-node-bundler-plugins","tags":["javascript","typescript"],"install":[{"cmd":"npm install opentelemetry-node-bundler-plugin-utils","lang":"bash","label":"npm"},{"cmd":"yarn add opentelemetry-node-bundler-plugin-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add opentelemetry-node-bundler-plugin-utils","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily an internal utility for bundler plugin development. The package ships with TypeScript types.","wrong":"const { getOpenTelemetryInstrumentationList } = require('@opentelemetry/node-bundler-plugin-utils');","symbol":"getOpenTelemetryInstrumentationList","correct":"import { getOpenTelemetryInstrumentationList } from '@opentelemetry/node-bundler-plugin-utils';"},{"note":"Exports are typically named. Avoid default import as it is not provided.","wrong":"import getPackageJsonDependencies from '@opentelemetry/node-bundler-plugin-utils';","symbol":"getPackageJsonDependencies","correct":"import { getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';"},{"note":"Used by bundler plugins to create a `require` function relative to a specific path, often for dynamic module loading. Intended for internal plugin logic.","wrong":"const createRequire = require('@opentelemetry/node-bundler-plugin-utils').createRequire;","symbol":"createRequire","correct":"import { createRequire } from '@opentelemetry/node-bundler-plugin-utils';"}],"quickstart":{"code":"import { getOpenTelemetryInstrumentationList, getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\ninterface PackageJson {dependencies?: Record<string, string>; devDependencies?: Record<string, string>;}\n\nasync function simulateBundlerPluginLogic(projectRoot: string) {\n  const packageJsonPath = path.join(projectRoot, 'package.json');\n  if (!fs.existsSync(packageJsonPath)) {\n    console.error(`Error: package.json not found at ${packageJsonPath}`);\n    return;\n  }\n\n  const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n  const packageJson: PackageJson = JSON.parse(packageJsonContent);\n\n  // Example 1: Get all dependencies from package.json\n  const allDependencies = getPackageJsonDependencies(packageJson);\n  console.log('Detected dependencies:', Object.keys(allDependencies));\n\n  // Example 2: Identify installed OpenTelemetry instrumentations\n  // In a real scenario, this might involve more sophisticated path resolution\n  const instrumentations = await getOpenTelemetryInstrumentationList(projectRoot);\n  console.log('Detected OpenTelemetry Instrumentations:', instrumentations);\n\n  if (instrumentations.length > 0) {\n    console.log(`\nBundler plugin would now configure/apply transformations for the following instrumentations:\n  - ${instrumentations.join('\\n  - ')}\n`);\n  } else {\n    console.log('\\nNo OpenTelemetry instrumentations detected for bundling.');\n  }\n}\n\n// To run this, create a dummy package.json in a 'test-project' directory\n// e.g., test-project/package.json with {\"dependencies\": {\"@opentelemetry/instrumentation-http\": \"^0.30.0\"}}\n// and run 'npm install' inside test-project.\n// Then execute this script, pointing to the test-project root.\n// For demonstration, we'll use current directory assuming it's a test project:\nsimulateBundlerPluginLogic(process.cwd()).catch(console.error);","lang":"typescript","description":"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."},"warnings":[{"fix":"Avoid direct consumption of this package. Instead, use official OpenTelemetry instrumentation libraries or bundler plugins that internally utilize this utility.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"As 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.","severity":"breaking","affected_versions":">=0.1.0"},{"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.","message":"Path 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.7.0':75 '1.0.0':88 'achiev':102 'across':115 'api':77 'applic':34 'author':54 'bundler':2,9,24,47,99 'chang':85 'consid':80 'consist':114 'context':71 'creat':66 'crucial':93 'current':72 'depend':40,64 'design':20 'develop':22,35 'differ':116 'direct':31 'duplic':111 'ecosystem':49 'ensur':113 'form':91 'foundat':94 'function':68 'goal':105 'help':52 'identifi':58 'implement':118 'instal':59 'instrument':61,104 'intend':29 'intern':17 'javascript':119 'layer':95 'librari':51 'like':57 'logic':108 'node':8 'offer':106 'opentelemetri':1,7,23,46,60,98 'opentelemetry-node-bundler-plugin-util':6 'packag':12,43 'package.json':63 'pars':62 'plugin':3,10,25,48,53,100,117 'provid':13 'rather':37 'reduc':110 'releas':89 'requir':67 'set':15 'share':107 'specif':19,70 'subject':83 'task':56 'typescript':120 'unstabl':81 'use':32 'util':4,11,18 'version':74 'within':44","created_at":"2026-04-20T01:55:57.062459+00:00","updated_at":"2026-04-20T01:55:57.062459+00:00","problems":[{"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.","cause":"The package is not installed or the import path is incorrect.","error":"Cannot find module '@opentelemetry/node-bundler-plugin-utils'"},{"fix":"Ensure you are using named imports for functions like `getPackageJsonDependencies`: `import { getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';`","cause":"Attempting to use a named export via a default import, or destructuring from an undefined import.","error":"TypeError: Cannot read properties of undefined (reading 'getPackageJsonDependencies')"},{"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.","cause":"Trying to import a symbol that does not exist or has been removed from the package's public API.","error":"TS2305: Module '\"@opentelemetry/node-bundler-plugin-utils\"' has no exported member 'SomeNonExistentExport'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/DrewCorlin/opentelemetry-node-bundler-plugins","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/opentelemetry-node-bundler-plugin-utils","openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}