{"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install opentelemetry-node-bundler-plugin-utils"],"cli":null},"imports":["import { getOpenTelemetryInstrumentationList } from '@opentelemetry/node-bundler-plugin-utils';","import { getPackageJsonDependencies } from '@opentelemetry/node-bundler-plugin-utils';","import { createRequire } from '@opentelemetry/node-bundler-plugin-utils';"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}