Skip to content
Latchkey

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.

node
@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 allowed

Common 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

  1. Move SDK start into a single global setup, not a per-file import.
  2. Use Jest globalSetup/setupFilesAfterEach so registration happens once.
  3. For unit tests that do not need tracing, disable the SDK instead.
jest.config.js
// 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.

test/otel-setup.js
const { trace } = require('@opentelemetry/api');
trace.disable();   // clears the global before re-registering

How 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.

Frequently asked questions

What causes ""existing ... TracerProvider" registration"?
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.
How do I fix "existing ... TracerProvider" registration?
Register the SDK once, globally

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card