Registry / observability / opentelemetry-rollup-plugin-node

opentelemetry-rollup-plugin-node

JSON →
library4.4.0jsnpmunverified

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.

npm install opentelemetry-rollup-plugin-node
INSTALL
IMPORT
SIG · OPENTELEMETRY-ROLL
O
opentelemetry-rollup-plugin-node
observabilityjavascriptv4.4.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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

openTelemetryPlugin
import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node'
const openTelemetryPlugin = require('opentelemetry-rollup-plugin-node')
ESM-only; the package does not provide a CommonJS export. Use dynamic import if needed in CJS context.
openTelemetryPlugin
const { openTelemetryPlugin } = await import('opentelemetry-rollup-plugin-node')
const openTelemetryPlugin = require('opentelemetry-rollup-plugin-node')
For CommonJS projects, use dynamic import. The package does not ship CJS.
openTelemetryPlugin
import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node'
import defaultExport from 'opentelemetry-rollup-plugin-node'
This is a named export, not a default export. Default import will give undefined.

Shows how to configure rollup with the OpenTelemetry plugin, including all required rollup plugins and basic instrumentation setup.

import { rollup } from 'rollup'; import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node'; import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; import path from 'path'; import typescript from '@rollup/plugin-typescript'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; async function build() { const bundle = await rollup({ input: path.normalize(__dirname + '/../src/app.ts'), plugins: [ nodeResolve({ extensions: ['.mjs', '.js', '.json', '.ts'] }), openTelemetryPlugin({ instrumentations: getNodeAutoInstrumentations({ '@opentelemetry/instrumentation-pino': { logKeys: { traceId: 'traceId', spanId: 'spanId', traceFlags: 'traceFlags', }, }, }), }), commonjs(), json(), typescript({ tsconfig: path.normalize(__dirname + '/../tsconfig.json'), sourceMap: false }), ], }); await bundle.write({ file: path.normalize(__dirname + '/../dist/app.js'), format: 'cjs' }); await bundle.close(); } build().catch(console.error);
Debug
Known issues
gotchaThe 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.
fix
Use @opentelemetry/sdk-node with getNodeAutoInstrumentations for builtins, or configure builtin instrumentations manually via the plugin's builtinInstrumentations option if available.
affects: >=4.0.0
deprecatedThe externalModules option might be removed or renamed in future releases.
fix
Use rollup's native external option instead.
affects: >=4.4.0
breakingESM-only: package no longer provides CommonJS exports since v3.0.0.
fix
Use import statement or dynamic import. Do not use require().
affects: >=3.0.0
gotchaThe plugin must be placed after nodeResolve in the plugins array to ensure module resolution works correctly.
fix
Order plugins as shown in the quickstart: nodeResolve first, then openTelemetryPlugin, then commonjs, json, typescript.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Must use import to load ES Module: /path/to/node_modules/opentelemetry-rollup-plugin-node/dist/index.js
Attempting to require() an ES Module with CommonJS require().
fix
Change to dynamic import: const { openTelemetryPlugin } = await import('opentelemetry-rollup-plugin-node');
TypeError: openTelemetryPlugin is not a function
Default import used instead of named import, resulting in undefined.
fix
Use named import: import { openTelemetryPlugin } from 'opentelemetry-rollup-plugin-node';
Error: Cannot find module '@opentelemetry/auto-instrumentations-node'
Missing required peer dependency.
fix
Install the package: npm install @opentelemetry/auto-instrumentations-node
Upgrade
Version history
4.4.0latest on npm
Audit
Dependencies
rollupoptionalpeer dependency required at runtime
@opentelemetry/auto-instrumentations-nodeoptionalrecommended package to get instrumentations to pass to plugin
Agent activity
32 hits · last 30 days
node
30
OpenAI (training)
2
Resources
opentelemetry-rollup-plugin-node — npm install opentelemetry-rollup-plugin-node · libregistry