Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
* refactor(sdk-metrics): use test() instead of match() in isValidName() [#6205](https://github.com/open-telemetry/opentelemetry-js/pull/6205) @cjihrig
* refactor(core): remove TimeOriginLegacy Safari <15 fallback [#6235](https://github.com/open-telemetry/opentelemetry-js/pull/6235) @overbalance
* chore: remove backcompat workspace [#6238](https://github.com/open-telemetry/opentelemetry-js/pull/6238) @overbalance
* refactor(core,resources): consolidate platform-specific code [#6208](https://github.com/open-telemetry/opentelemetry-js/pull/6208) @overbalance

## 2.2.0

Expand Down
26 changes: 1 addition & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,28 +297,4 @@ After adding the package, run `npm install` from the root of the project. This w

Universal packages are packages that can be used in both web browsers and
Node.js environment. These packages may be implemented on top of different
platform APIs to achieve the same goal. Like accessing the _global_ reference,
we have different preferred ways to do it:

- In Node.js, we access the _global_ reference with `globalThis` or `global`:

```js
/// packages/opentelemetry-core/src/platform/node/globalThis.ts
export const _globalThis = typeof globalThis === 'object' ? globalThis : global;
```

- In web browser, we access the _global_ reference with the following definition:

```js
/// packages/opentelemetry-core/src/platform/browser/globalThis.ts
export const _globalThis: typeof globalThis =
typeof globalThis === 'object' ? globalThis :
typeof self === 'object' ? self :
typeof window === 'object' ? window :
typeof global === 'object' ? global :
{} as typeof globalThis;
```

Even though the implementation may differ, the exported names must be aligned.
It can be confusing if exported names present in one environment but not in the
others.
platform APIs to achieve the same goal.
1 change: 1 addition & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fix(api): prioritize `esnext` export condition as it is more specific [#5458](ht
* refactor(api): remove "export *" in favor of explicit named exports [#4880](https://github.com/open-telemetry/opentelemetry-js/pull/4880) @robbkidd
* chore: enable tsconfig isolatedModules [#5697](https://github.com/open-telemetry/opentelemetry-js/pull/5697) @legendecas
* chore: disallow constructor parameter property syntax [#6187](https://github.com/open-telemetry/opentelemetry-js/pull/6187) @legendecas
* refactor(api): remove platform-specific globalThis, use globalThis directly [#6208](https://github.com/open-telemetry/opentelemetry-js/pull/6208) @overbalance

## 1.9.0

Expand Down
6 changes: 0 additions & 6 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"exports": {
".": {
"esnext": "./build/esnext/index.js",
Expand Down
3 changes: 1 addition & 2 deletions api/src/internal/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { MeterProvider } from '../metrics/MeterProvider';
import { ContextManager } from '../context/types';
import { DiagLogger } from '../diag/types';
import { _globalThis } from '../platform';
import { TextMapPropagator } from '../propagation/TextMapPropagator';
import type { TracerProvider } from '../trace/tracer_provider';
import { VERSION } from '../version';
Expand All @@ -28,7 +27,7 @@ const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(
`opentelemetry.js.api.${major}`
);

const _global = _globalThis as OTelGlobal;
const _global = globalThis as OTelGlobal;

export function registerGlobal<Type extends keyof OTelGlobalAPI>(
type: Type,
Expand Down
38 changes: 0 additions & 38 deletions api/src/platform/browser/globalThis.ts

This file was deleted.

17 changes: 0 additions & 17 deletions api/src/platform/browser/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions api/src/platform/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions api/src/platform/node/globalThis.ts

This file was deleted.

5 changes: 2 additions & 3 deletions api/test/common/internal/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import { getGlobal } from '../../../src/internal/global-utils';
import { _globalThis } from '../../../src/platform';
import { NoopContextManager } from '../../../src/context/NoopContextManager';
import { DiagLogLevel } from '../../../src/diag/types';

Expand Down Expand Up @@ -56,7 +55,7 @@ describe('Global Utils', function () {
api1.trace.disable();
api1.diag.disable();
// @ts-expect-error we are modifying internals for testing purposes here
delete _globalThis[Symbol.for(GLOBAL_API_SYMBOL_KEY)];
delete globalThis[Symbol.for(GLOBAL_API_SYMBOL_KEY)];
});

it('should change the global context manager', function () {
Expand Down Expand Up @@ -92,7 +91,7 @@ describe('Global Utils', function () {
const globalInstance = getGlobal('diag');
assert.ok(globalInstance);
// @ts-expect-error we are modifying internals for testing purposes here
_globalThis[Symbol.for(GLOBAL_API_SYMBOL_KEY)].version = '0.0.1';
globalThis[Symbol.for(GLOBAL_API_SYMBOL_KEY)].version = '0.0.1';

assert.equal(false, api1.diag.setLogger(logger2)); // won't happen

Expand Down
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
* test(otlp-transformer): add benchmark for ProtobufTraceSerializer [#6226](https://github.com/open-telemetry/opentelemetry-js/pull/6226) @overbalance
* chore(backcompat): fix backcompat tests and tsconfig cleanup [#6232](https://github.com/open-telemetry/opentelemetry-js/pull/6232) @overbalance
* refactor(instrumentation-http): refactor getIncomingRequestAttributes() to reduce work [#6207](https://github.com/open-telemetry/opentelemetry-js/pull/6207) @cjihrig
* refactor(api-logs,instrumentation-fetch): remove platform-specific globalThis, use globalThis directly [#6208](https://github.com/open-telemetry/opentelemetry-js/pull/6208) @overbalance

## 0.208.0

Expand Down
6 changes: 0 additions & 6 deletions experimental/packages/api-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"types": "build/src/index.d.ts",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"prepublishOnly": "npm run compile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { LoggerProvider } from '../types/LoggerProvider';
import { _globalThis } from '../platform';

export const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs');

Expand All @@ -24,7 +23,7 @@ type OtelGlobal = Partial<{
[GLOBAL_LOGS_API_KEY]: Get<LoggerProvider>;
}>;

export const _global = _globalThis as OtelGlobal;
export const _global = globalThis as OtelGlobal;
Comment thread
pichlermarc marked this conversation as resolved.

/**
* Make a function which accepts a version integer and returns the instance of an API if the version
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions experimental/packages/api-logs/src/platform/browser/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions experimental/packages/api-logs/src/platform/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions experimental/packages/api-logs/src/platform/node/globalThis.ts

This file was deleted.

17 changes: 0 additions & 17 deletions experimental/packages/api-logs/src/platform/node/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
serverPortFromUrl,
} from './utils';
import { VERSION } from './version';
import { _globalThis } from '@opentelemetry/core';

// how long to wait for observer to collect information about resources
// this is needed as event "load" is called before observer
Expand Down Expand Up @@ -658,10 +657,10 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
return;
}
if (isWrapped(fetch)) {
this._unwrap(_globalThis, 'fetch');
this._unwrap(globalThis, 'fetch');
this._diag.debug('removing previous patch for constructor');
}
this._wrap(_globalThis, 'fetch', this._patchConstructor());
this._wrap(globalThis, 'fetch', this._patchConstructor());
}

/**
Expand All @@ -671,7 +670,7 @@ export class FetchInstrumentation extends InstrumentationBase<FetchInstrumentati
if (!hasBrowserPerformanceAPI) {
return;
}
this._unwrap(_globalThis, 'fetch');
this._unwrap(globalThis, 'fetch');
this._usedResources = new WeakSet<PerformanceResourceTiming>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

export { _globalThis } from './globalThis';
/**
* @deprecated Use globalThis directly instead.
*/
export const _globalThis = globalThis;
Loading