Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: include major version in the API global symbol
This will prevent any chance of a version X API interfering with a
version Y API if X and Y are different major versions.
  • Loading branch information
dyladan committed Feb 26, 2021
commit 3afeda0a9c39ee9c4eb5f38f76a5eec7744172d1
5 changes: 4 additions & 1 deletion src/internal/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import type { TracerProvider } from '../trace/tracer_provider';
import { VERSION } from '../version';
import { isCompatible } from './semver';

const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for('io.opentelemetry.js.api');
const major = VERSION.split('.')[0];
const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(
`io.opentelemetry.js.api.${major}`
);

const _global = _globalThis as OTelGlobal;

Expand Down
4 changes: 2 additions & 2 deletions test/internal/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Global Utils', () => {
api1.trace.disable();
api1.diag.disable();
// @ts-expect-error we are modifying internals for testing purposes here
delete _globalThis[Symbol.for('io.opentelemetry.js.api')];
delete _globalThis[Symbol.for('io.opentelemetry.js.api.0')];
});

it('should change the global context manager', () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Global Utils', () => {
const globalInstance = getGlobal('context');
assert.ok(globalInstance);
// @ts-expect-error we are modifying internals for testing purposes here
_globalThis[Symbol.for('io.opentelemetry.js.api')].version = '0.0.1';
_globalThis[Symbol.for('io.opentelemetry.js.api.0')].version = '0.0.1';

assert.strictEqual(api1.context['_getContextManager'](), original);
});
Expand Down