{"id":21662,"library":"opentelemetry-rollup-plugin-node","title":"OpenTelemetry Rollup Plugin Node","description":"Rollup plugin that bundles OpenTelemetry Node.js core and contrib instrumentations into your code during build. Current stable version is 4.4.0, released periodically as part of the opentelemetry-node-bundler-plugins monorepo. Key differentiator: it allows bundling OpenTelemetry instrumentation for deployment in serverless or embedded scenarios where runtime patching is not possible. Requires rollup and several peer dependencies, and works alongside other rollup plugins for TypeScript and CommonJS support. Note that it only patches non-builtin modules from opentelemetry-js-contrib, so builtin modules and SDK configuration must be handled separately.","status":"active","version":"4.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/DrewCorlin/opentelemetry-node-bundler-plugins","tags":["javascript","opentelemetry","bundler","rollup","typescript"],"install":[{"cmd":"npm install opentelemetry-rollup-plugin-node","lang":"bash","label":"npm"},{"cmd":"yarn add opentelemetry-rollup-plugin-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add opentelemetry-rollup-plugin-node","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required at runtime","package":"rollup","optional":true},{"reason":"recommended package to get instrumentations to pass to plugin","package":"@opentelemetry/auto-instrumentations-node","optional":true}],"imports":[{"note":"ESM-only; the package does not provide a CommonJS export. Use dynamic import if needed in CJS context.","wrong":"const openTelemetryPlugin = require('opentelemetry-rollup-plugin-node')","symbol":"openTelemetryPlugin","correct":"import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node'"},{"note":"For CommonJS projects, use dynamic import. The package does not ship CJS.","wrong":"const openTelemetryPlugin = require('opentelemetry-rollup-plugin-node')","symbol":"openTelemetryPlugin","correct":"const { openTelemetryPlugin } = await import('opentelemetry-rollup-plugin-node')"},{"note":"This is a named export, not a default export. Default import will give undefined.","wrong":"import defaultExport from 'opentelemetry-rollup-plugin-node'","symbol":"openTelemetryPlugin","correct":"import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node'"}],"quickstart":{"code":"import { rollup } from 'rollup';\nimport { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport path from 'path';\nimport typescript from '@rollup/plugin-typescript';\nimport commonjs from '@rollup/plugin-commonjs';\nimport nodeResolve from '@rollup/plugin-node-resolve';\nimport json from '@rollup/plugin-json';\n\nasync function build() {\n  const bundle = await rollup({\n    input: path.normalize(__dirname + '/../src/app.ts'),\n    plugins: [\n      nodeResolve({ extensions: ['.mjs', '.js', '.json', '.ts'] }),\n      openTelemetryPlugin({\n        instrumentations: getNodeAutoInstrumentations({\n          '@opentelemetry/instrumentation-pino': {\n            logKeys: {\n              traceId: 'traceId',\n              spanId: 'spanId',\n              traceFlags: 'traceFlags',\n            },\n          },\n        }),\n      }),\n      commonjs(),\n      json(),\n      typescript({ tsconfig: path.normalize(__dirname + '/../tsconfig.json'), sourceMap: false }),\n    ],\n  });\n  await bundle.write({ file: path.normalize(__dirname + '/../dist/app.js'), format: 'cjs' });\n  await bundle.close();\n}\n\nbuild().catch(console.error);","lang":"typescript","description":"Shows how to configure rollup with the OpenTelemetry plugin, including all required rollup plugins and basic instrumentation setup."},"warnings":[{"fix":"Use @opentelemetry/sdk-node with getNodeAutoInstrumentations for builtins, or configure builtin instrumentations manually via the plugin's builtinInstrumentations option if available.","message":"The plugin only instruments non-builtin modules from opentelemetry-js-contrib. Builtin modules (like http, fs) are not patched and must be handled separately with the NodeSDK.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use rollup's native external option instead.","message":"The externalModules option might be removed or renamed in future releases.","severity":"deprecated","affected_versions":">=4.4.0"},{"fix":"Use import statement or dynamic import. Do not use require().","message":"ESM-only: package no longer provides CommonJS exports since v3.0.0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Order plugins as shown in the quickstart: nodeResolve first, then openTelemetryPlugin, then commonjs, json, typescript.","message":"The plugin must be placed after nodeResolve in the plugins array to ensure module resolution works correctly.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to dynamic import: const { openTelemetryPlugin } = await import('opentelemetry-rollup-plugin-node');","cause":"Attempting to require() an ES Module with CommonJS require().","error":"Error: Must use import to load ES Module: /path/to/node_modules/opentelemetry-rollup-plugin-node/dist/index.js"},{"fix":"Use named import: import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node';","cause":"Default import used instead of named import, resulting in undefined.","error":"TypeError: openTelemetryPlugin is not a function"},{"fix":"Install the package: npm install @opentelemetry/auto-instrumentations-node","cause":"Missing required peer dependency.","error":"Error: Cannot find module '@opentelemetry/auto-instrumentations-node'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}