OpenTelemetry JS "Registration of existing global TracerProvider" in CI
The OTel API stores a single global TracerProvider. When test setup registers a provider more than once (imported by many test files, or re-run per suite), the API refuses the second registration and warns, leaving instrumentation in an inconsistent state.
What this error means
The diagnostic log repeats "Registration of existing global tracer provider" (and similarly for meter/context/propagation), and spans are dropped or attributed to the wrong provider across test files.
@opentelemetry/api: Registration of existing global tracer provider,
overriding it is not allowed
@opentelemetry/api: Registration of existing global context manager,
overriding it is not allowedCommon causes
SDK setup runs once per test file
Jest isolates modules per test file, so a tracing.js that calls provider.register() at import time runs again for each file, and the API rejects the repeat registration.
Both auto and manual registration happen
The @opentelemetry/sdk-node NodeSDK and an explicit provider.register() both try to set the global provider, colliding on the second call.
How to fix it
Register the SDK once, globally
- Move SDK start into a single global setup, not a per-file import.
- Use Jest
globalSetup/setupFilesAfterEachso registration happens once. - For unit tests that do not need tracing, disable the SDK instead.
// jest.config.js
module.exports = { globalSetup: '<rootDir>/test/otel-setup.js' };Reset the global API between suites if needed
When a suite must re-register, disable the previous global provider first so the new one is accepted.
const { trace } = require('@opentelemetry/api');
trace.disable(); // clears the global before re-registeringHow to prevent it
- Register the tracer provider exactly once per process.
- Do not call provider.register() at module import in shared test files.
- Choose either NodeSDK or a manual provider, not both.