diff --git a/api/package.json b/api/package.json index 78f9f03b79..f7a82690f0 100644 --- a/api/package.json +++ b/api/package.json @@ -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": { ".": { "module": "./build/esm/index.js", @@ -77,6 +71,7 @@ "access": "public" }, "devDependencies": { + "@opentelemetry/platform-common": "1.26.0", "@types/mocha": "10.0.8", "@types/node": "18.6.5", "@types/sinon": "17.0.3", diff --git a/api/src/internal/global-utils.ts b/api/src/internal/global-utils.ts index b8c5fb16db..e95a9bcbea 100644 --- a/api/src/internal/global-utils.ts +++ b/api/src/internal/global-utils.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { MeterProvider } from '../metrics/MeterProvider'; +import { _globalThis } from '@opentelemetry/platform-common'; import { ContextManager } from '../context/types'; import { DiagLogger } from '../diag/types'; -import { _globalThis } from '../platform'; +import { MeterProvider } from '../metrics/MeterProvider'; import { TextMapPropagator } from '../propagation/TextMapPropagator'; import type { TracerProvider } from '../trace/tracer_provider'; import { VERSION } from '../version'; diff --git a/api/src/platform/browser/globalThis.ts b/api/src/platform/browser/globalThis.ts deleted file mode 100644 index f09378a95e..0000000000 --- a/api/src/platform/browser/globalThis.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Updates to this file should also be replicated to @opentelemetry/core too. - -/** - * - globalThis (New standard) - * - self (Will return the current window instance for supported browsers) - * - window (fallback for older browser implementations) - * - global (NodeJS implementation) - * - (When all else fails) - */ - -/** only globals that common to node and browsers are allowed */ -// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef -export const _globalThis: typeof globalThis = - typeof globalThis === 'object' - ? globalThis - : typeof self === 'object' - ? self - : typeof window === 'object' - ? window - : typeof global === 'object' - ? global - : ({} as typeof globalThis); diff --git a/api/test/common/internal/global.test.ts b/api/test/common/internal/global.test.ts index 7a630c22ce..7248a9fee4 100644 --- a/api/test/common/internal/global.test.ts +++ b/api/test/common/internal/global.test.ts @@ -14,11 +14,11 @@ * limitations under the License. */ +import { _globalThis } from '@opentelemetry/platform-common'; import * as assert from 'assert'; -import { getGlobal } from '../../../src/internal/global-utils'; -import { _globalThis } from '../../../src/platform'; import { NoopContextManager } from '../../../src/context/NoopContextManager'; import { DiagLogLevel } from '../../../src/diag/types'; +import { getGlobal } from '../../../src/internal/global-utils'; import sinon = require('sinon'); const api1 = require('../../../src') as typeof import('../../../src'); diff --git a/api/tsconfig.esm.json b/api/tsconfig.esm.json index 0817b3decd..c620dfa79d 100644 --- a/api/tsconfig.esm.json +++ b/api/tsconfig.esm.json @@ -8,5 +8,9 @@ "include": [ "src/**/*.ts" ], - "references": [] + "references": [ + { + "path": "../packages/platform-common" + } + ] } diff --git a/api/tsconfig.esnext.json b/api/tsconfig.esnext.json index 54d1d053dc..a26cda606a 100644 --- a/api/tsconfig.esnext.json +++ b/api/tsconfig.esnext.json @@ -8,5 +8,9 @@ "include": [ "src/**/*.ts" ], - "references": [] + "references": [ + { + "path": "../packages/platform-common" + } + ] } diff --git a/api/tsconfig.json b/api/tsconfig.json index 9622af53cd..9c7c9f110b 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -9,5 +9,9 @@ "src/**/*.ts", "test/**/*.ts" ], - "references": [] + "references": [ + { + "path": "../packages/platform-common" + } + ] } diff --git a/experimental/packages/api-events/package.json b/experimental/packages/api-events/package.json index 66a7a27879..1c5c08abb7 100644 --- a/experimental/packages/api-events/package.json +++ b/experimental/packages/api-events/package.json @@ -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": { "build": "npm run compile", @@ -64,6 +58,7 @@ "@opentelemetry/api-logs": "0.53.0" }, "devDependencies": { + "@opentelemetry/platform-common": "1.26.0", "@types/mocha": "10.0.8", "@types/node": "18.6.5", "@types/webpack-env": "1.16.3", diff --git a/experimental/packages/api-events/src/internal/global-utils.ts b/experimental/packages/api-events/src/internal/global-utils.ts index 171cb0e1c7..dad494382a 100644 --- a/experimental/packages/api-events/src/internal/global-utils.ts +++ b/experimental/packages/api-events/src/internal/global-utils.ts @@ -14,8 +14,8 @@ * limitations under the License. */ +import { _globalThis } from '@opentelemetry/platform-common'; import { EventLoggerProvider } from '../types/EventLoggerProvider'; -import { _globalThis } from '../platform'; export const GLOBAL_EVENTS_API_KEY = Symbol.for( 'io.opentelemetry.js.api.events' diff --git a/experimental/packages/api-events/src/platform/browser/index.ts b/experimental/packages/api-events/src/platform/browser/index.ts deleted file mode 100644 index e4d18640b4..0000000000 --- a/experimental/packages/api-events/src/platform/browser/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './globalThis'; diff --git a/experimental/packages/api-events/src/platform/index.ts b/experimental/packages/api-events/src/platform/index.ts deleted file mode 100644 index a6deb70b17..0000000000 --- a/experimental/packages/api-events/src/platform/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './node'; diff --git a/experimental/packages/api-events/src/platform/node/globalThis.ts b/experimental/packages/api-events/src/platform/node/globalThis.ts deleted file mode 100644 index 36e97e2732..0000000000 --- a/experimental/packages/api-events/src/platform/node/globalThis.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** only globals that common to node and browsers are allowed */ -// eslint-disable-next-line node/no-unsupported-features/es-builtins -export const _globalThis = typeof globalThis === 'object' ? globalThis : global; diff --git a/experimental/packages/api-events/src/platform/node/index.ts b/experimental/packages/api-events/src/platform/node/index.ts deleted file mode 100644 index e4d18640b4..0000000000 --- a/experimental/packages/api-events/src/platform/node/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './globalThis'; diff --git a/experimental/packages/api-logs/package.json b/experimental/packages/api-logs/package.json index c5204f6311..ec5e120366 100644 --- a/experimental/packages/api-logs/package.json +++ b/experimental/packages/api-logs/package.json @@ -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", @@ -63,6 +57,7 @@ "@opentelemetry/api": "^1.3.0" }, "devDependencies": { + "@opentelemetry/platform-common": "1.26.0", "@types/mocha": "10.0.8", "@types/node": "18.6.5", "@types/webpack-env": "1.16.3", diff --git a/experimental/packages/api-logs/src/internal/global-utils.ts b/experimental/packages/api-logs/src/internal/global-utils.ts index 6325db8144..283fcb23c9 100644 --- a/experimental/packages/api-logs/src/internal/global-utils.ts +++ b/experimental/packages/api-logs/src/internal/global-utils.ts @@ -14,8 +14,8 @@ * limitations under the License. */ +import { _globalThis } from '@opentelemetry/platform-common'; import { LoggerProvider } from '../types/LoggerProvider'; -import { _globalThis } from '../platform'; export const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs'); diff --git a/experimental/packages/api-logs/src/platform/browser/globalThis.ts b/experimental/packages/api-logs/src/platform/browser/globalThis.ts deleted file mode 100644 index e8a79351b2..0000000000 --- a/experimental/packages/api-logs/src/platform/browser/globalThis.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Updates to this file should also be replicated to @opentelemetry/api and -// @opentelemetry/core too. - -/** - * - globalThis (New standard) - * - self (Will return the current window instance for supported browsers) - * - window (fallback for older browser implementations) - * - global (NodeJS implementation) - * - (When all else fails) - */ - -/** only globals that common to node and browsers are allowed */ -// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef -export const _globalThis: typeof globalThis = - typeof globalThis === 'object' - ? globalThis - : typeof self === 'object' - ? self - : typeof window === 'object' - ? window - : typeof global === 'object' - ? global - : ({} as typeof globalThis); diff --git a/experimental/packages/api-logs/src/platform/browser/index.ts b/experimental/packages/api-logs/src/platform/browser/index.ts deleted file mode 100644 index e4d18640b4..0000000000 --- a/experimental/packages/api-logs/src/platform/browser/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './globalThis'; diff --git a/experimental/packages/api-logs/src/platform/index.ts b/experimental/packages/api-logs/src/platform/index.ts deleted file mode 100644 index a6deb70b17..0000000000 --- a/experimental/packages/api-logs/src/platform/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './node'; diff --git a/experimental/packages/api-logs/src/platform/node/index.ts b/experimental/packages/api-logs/src/platform/node/index.ts deleted file mode 100644 index e4d18640b4..0000000000 --- a/experimental/packages/api-logs/src/platform/node/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { _globalThis } from './globalThis'; diff --git a/experimental/packages/exporter-logs-otlp-http/package.json b/experimental/packages/exporter-logs-otlp-http/package.json index e60e0fbf8f..d5e13a582c 100644 --- a/experimental/packages/exporter-logs-otlp-http/package.json +++ b/experimental/packages/exporter-logs-otlp-http/package.json @@ -12,11 +12,19 @@ "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": { + ".": { + "browser": { + "module": "./build/esm/platform/browser/index.js", + "esnext": "./build/esnext/platform/browser/index.js", + "types": "./build/src/platform/browser/index.d.ts", + "default": "./build/src/platform/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } }, "repository": { "type": "git", @@ -70,6 +78,7 @@ ], "sideEffects": false, "devDependencies": { + "@opentelemetry/platform-common": "1.26.0", "@babel/core": "7.25.2", "@babel/preset-env": "7.25.4", "@opentelemetry/api": "1.9.0", diff --git a/experimental/packages/exporter-logs-otlp-proto/package.json b/experimental/packages/exporter-logs-otlp-proto/package.json index 03cbfef200..a018139bff 100644 --- a/experimental/packages/exporter-logs-otlp-proto/package.json +++ b/experimental/packages/exporter-logs-otlp-proto/package.json @@ -7,11 +7,19 @@ "esnext": "build/esnext/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", - "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": { + ".": { + "browser": { + "module": "./build/esm/platform/browser/index.js", + "esnext": "./build/esnext/platform/browser/index.js", + "types": "./build/src/platform/browser/index.d.ts", + "default": "./build/src/platform/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } }, "scripts": { "prepublishOnly": "npm run compile", diff --git a/experimental/packages/exporter-trace-otlp-http/package.json b/experimental/packages/exporter-trace-otlp-http/package.json index d1570027ba..32113ed53f 100644 --- a/experimental/packages/exporter-trace-otlp-http/package.json +++ b/experimental/packages/exporter-trace-otlp-http/package.json @@ -7,11 +7,19 @@ "esnext": "build/esnext/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", - "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": { + ".": { + "browser": { + "module": "./build/esm/platform/browser/index.js", + "esnext": "./build/esnext/platform/browser/index.js", + "types": "./build/src/platform/browser/index.d.ts", + "default": "./build/src/platform/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } }, "scripts": { "prepublishOnly": "npm run compile", diff --git a/experimental/packages/exporter-trace-otlp-proto/package.json b/experimental/packages/exporter-trace-otlp-proto/package.json index fdb271449e..e91dcd4be7 100644 --- a/experimental/packages/exporter-trace-otlp-proto/package.json +++ b/experimental/packages/exporter-trace-otlp-proto/package.json @@ -7,11 +7,19 @@ "esnext": "build/esnext/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", - "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": { + ".": { + "browser": { + "module": "./build/esm/platform/browser/index.js", + "esnext": "./build/esnext/platform/browser/index.js", + "types": "./build/src/platform/browser/index.d.ts", + "default": "./build/src/platform/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } }, "scripts": { "prepublishOnly": "npm run compile", diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index c71ed8cbf2..c50f989a8e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -7,11 +7,19 @@ "esnext": "build/esnext/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", - "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": { + ".": { + "browser": { + "module": "./build/esm/platform/browser/index.js", + "esnext": "./build/esnext/platform/browser/index.js", + "types": "./build/src/platform/browser/index.d.ts", + "default": "./build/src/platform/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } }, "scripts": { "prepublishOnly": "npm run compile", diff --git a/package-lock.json b/package-lock.json index 7c2b6ecdd6..25cdb2ff6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "version": "1.9.0", "license": "Apache-2.0", "devDependencies": { + "@opentelemetry/platform-common": "1.26.0", "@types/mocha": "10.0.8", "@types/node": "18.6.5", "@types/sinon": "17.0.3", @@ -6013,6 +6014,10 @@ "resolved": "experimental/packages/otlp-transformer", "link": true }, + "node_modules/@opentelemetry/platform-common": { + "resolved": "packages/platform-common", + "link": true + }, "node_modules/@opentelemetry/propagator-aws-xray": { "resolved": "packages/propagator-aws-xray", "link": true @@ -29191,6 +29196,19 @@ "@opentelemetry/api": ">=1.0.0 <1.10.0" } }, + "packages/platform-common": { + "version": "1.26.0", + "license": "Apache-2.0", + "devDependencies": { + "@types/node": "18.6.5", + "cross-var": "1.1.0", + "lerna": "6.6.2", + "typescript": "4.4.4" + }, + "engines": { + "node": ">=14" + } + }, "packages/propagator-aws-xray": { "name": "@opentelemetry/propagator-aws-xray", "version": "1.26.0", @@ -32550,6 +32568,7 @@ "@opentelemetry/api": { "version": "file:api", "requires": { + "@opentelemetry/platform-common": "1.26.0", "@types/mocha": "10.0.8", "@types/node": "18.6.5", "@types/sinon": "17.0.3", @@ -33371,6 +33390,15 @@ "webpack": "5.94.0" } }, + "@opentelemetry/platform-common": { + "version": "file:packages/platform-common", + "requires": { + "@types/node": "18.6.5", + "cross-var": "1.1.0", + "lerna": "6.6.2", + "typescript": "4.4.4" + } + }, "@opentelemetry/propagator-aws-xray": { "version": "file:packages/propagator-aws-xray", "requires": { diff --git a/packages/platform-common/.eslintignore b/packages/platform-common/.eslintignore new file mode 100644 index 0000000000..9ef96044fa --- /dev/null +++ b/packages/platform-common/.eslintignore @@ -0,0 +1,2 @@ +build + diff --git a/packages/platform-common/.eslintrc.js b/packages/platform-common/.eslintrc.js new file mode 100644 index 0000000000..36847df9fb --- /dev/null +++ b/packages/platform-common/.eslintrc.js @@ -0,0 +1,9 @@ +module.exports = { + "env": { + "mocha": true, + "commonjs": true, + "node": true, + "browser": true + }, + ...require('../../eslint.base.js') +} diff --git a/packages/platform-common/.npmignore b/packages/platform-common/.npmignore new file mode 100644 index 0000000000..9505ba9450 --- /dev/null +++ b/packages/platform-common/.npmignore @@ -0,0 +1,4 @@ +/bin +/coverage +/doc +/test diff --git a/packages/platform-common/LICENSE b/packages/platform-common/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/packages/platform-common/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/platform-common/README.md b/packages/platform-common/README.md new file mode 100644 index 0000000000..e42517a3fa --- /dev/null +++ b/packages/platform-common/README.md @@ -0,0 +1,9 @@ +# `@opentelemetry/template` + +> TODO: description + +## Usage + +```typescript +// TODO: DEMONSTRATE API +``` diff --git a/experimental/packages/api-logs/src/platform/node/globalThis.ts b/packages/platform-common/karma.conf.js similarity index 65% rename from experimental/packages/api-logs/src/platform/node/globalThis.ts rename to packages/platform-common/karma.conf.js index 36e97e2732..3019564a15 100644 --- a/experimental/packages/api-logs/src/platform/node/globalThis.ts +++ b/packages/platform-common/karma.conf.js @@ -1,11 +1,11 @@ -/* +/*! * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,11 @@ * limitations under the License. */ -/** only globals that common to node and browsers are allowed */ -// eslint-disable-next-line node/no-unsupported-features/es-builtins -export const _globalThis = typeof globalThis === 'object' ? globalThis : global; +const karmaWebpackConfig = require('../../karma.webpack'); +const karmaBaseConfig = require('../../karma.base'); + +module.exports = (config) => { + config.set(Object.assign({}, karmaBaseConfig, { + webpack: karmaWebpackConfig + })) +}; diff --git a/packages/platform-common/package.json b/packages/platform-common/package.json new file mode 100644 index 0000000000..c5a2a66012 --- /dev/null +++ b/packages/platform-common/package.json @@ -0,0 +1,116 @@ +{ + "name": "@opentelemetry/platform-common", + "version": "1.26.0", + "private": true, + "publishConfig": { + "access": "restricted" + }, + "description": "> TODO: description", + "author": "OpenTelemetry Authors", + "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/platform-common", + "license": "Apache-2.0", + "main": "build/src/index.js", + "module": "build/esm/index.js", + "esnext": "build/esnext/index.js", + "types": "build/src/index.d.ts", + "exports": { + ".": { + "browser": { + "module": "./build/esm/browser/index.js", + "esnext": "./build/esnext/browser/index.js", + "types": "./build/src/browser/index.d.ts", + "default": "./build/src/browser/index.js" + }, + "module": "./build/esm/index.js", + "esnext": "./build/esnext/index.js", + "types": "./build/src/index.d.ts", + "default": "./build/src/index.js" + } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/open-telemetry/opentelemetry-js.git" + }, + "bugs": { + "url": "https://github.com/open-telemetry/opentelemetry-js/issues" + }, + "engines": { + "node": ">=14" + }, + "scripts": { + "prepublishOnly": "npm run compile", + "compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "version": "node ../../scripts/version-update.js", + "clean": "tsc --build --clean", + "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies", + "prewatch": "npm run precompile", + "peer-api-check": "node ../../scripts/peer-api-check.js", + "align-api-deps": "node ../../scripts/align-api-deps.js" + }, + "Add these to scripts": { + "compile": "tsc --build", + "clean": "tsc --build --clean", + "test": "nyc mocha test/**/*.test.ts", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "version": "node ../../scripts/version-update.js", + "watch": "tsc --build --watch" + }, + "Add/change these to scripts if browser is supported": { + "compile": "tsc --build tsconfig.json", + "clean": "tsc --build --clean tsconfig.json", + "test:browser": "karma start --single-run", + "watch": "tsc --build --watch tsconfig.json" + }, + "keywords": [ + "opentelemetry", + "nodejs", + "browser", + "tracing", + "profiling", + "metrics", + "stats", + "monitoring" + ], + "files": [ + "build/src/**/*.js", + "build/src/**/*.js.map", + "build/src/**/*.d.ts", + "LICENSE", + "README.md" + ], + "sideEffects": false, + "Add these to files if browser is supported": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", + "build/esnext/**/*.js", + "build/esnext/**/*.js.map", + "build/esnext/**/*.d.ts" + ], + "devDependencies": { + "@types/node": "18.6.5", + "cross-var": "1.1.0", + "lerna": "6.6.2", + "typescript": "4.4.4" + }, + "Add these to devDependencies for testing": { + "@types/mocha": "9.1.1", + "@types/sinon": "10.0.13", + "mocha": "10.0.0", + "nyc": "15.1.0", + "sinon": "15.0.0" + }, + "Add these to devDependencies if browser is targeted": { + "@types/webpack-env": "1.16.0", + "babel-plugin-istanbul": "6.1.1", + "karma": "6.4.2", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.2.0", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.32", + "karma-webpack": "4.0.2", + "ts-loader": "8.4.0", + "webpack": "5.89.0" + } +} diff --git a/experimental/packages/api-events/src/platform/browser/globalThis.ts b/packages/platform-common/src/browser/globalThis.ts similarity index 100% rename from experimental/packages/api-events/src/platform/browser/globalThis.ts rename to packages/platform-common/src/browser/globalThis.ts diff --git a/api/src/platform/browser/index.ts b/packages/platform-common/src/browser/index.ts similarity index 100% rename from api/src/platform/browser/index.ts rename to packages/platform-common/src/browser/index.ts diff --git a/api/src/platform/index.ts b/packages/platform-common/src/index.ts similarity index 100% rename from api/src/platform/index.ts rename to packages/platform-common/src/index.ts diff --git a/api/src/platform/node/globalThis.ts b/packages/platform-common/src/node/globalThis.ts similarity index 100% rename from api/src/platform/node/globalThis.ts rename to packages/platform-common/src/node/globalThis.ts diff --git a/api/src/platform/node/index.ts b/packages/platform-common/src/node/index.ts similarity index 100% rename from api/src/platform/node/index.ts rename to packages/platform-common/src/node/index.ts diff --git a/packages/platform-common/tsconfig.esm.json b/packages/platform-common/tsconfig.esm.json new file mode 100644 index 0000000000..c43ba03ff0 --- /dev/null +++ b/packages/platform-common/tsconfig.esm.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "outDir": "build/esm", + "rootDir": "src", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ], + "references": [] +} diff --git a/packages/platform-common/tsconfig.esnext.json b/packages/platform-common/tsconfig.esnext.json new file mode 100644 index 0000000000..6eaaaf7d04 --- /dev/null +++ b/packages/platform-common/tsconfig.esnext.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.esnext.json", + "compilerOptions": { + "outDir": "build/esnext", + "rootDir": "src", + "tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ], + "references": [] +} diff --git a/packages/platform-common/tsconfig.json b/packages/platform-common/tsconfig.json new file mode 100644 index 0000000000..e94f4a6357 --- /dev/null +++ b/packages/platform-common/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "build", + "rootDir": "." + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ], + "references": [] +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 149b8f8394..b5f4ed97ed 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -86,6 +86,9 @@ { "path": "packages/opentelemetry-sdk-trace-web/tsconfig.esm.json" }, + { + "path": "packages/platform-common/tsconfig.esm.json" + }, { "path": "packages/propagator-aws-xray/tsconfig.esm.json" }, diff --git a/tsconfig.esnext.json b/tsconfig.esnext.json index 5f071fd224..c42e3fd066 100644 --- a/tsconfig.esnext.json +++ b/tsconfig.esnext.json @@ -86,6 +86,9 @@ { "path": "packages/opentelemetry-sdk-trace-web/tsconfig.esnext.json" }, + { + "path": "packages/platform-common/tsconfig.esnext.json" + }, { "path": "packages/propagator-aws-xray/tsconfig.esnext.json" }, diff --git a/tsconfig.json b/tsconfig.json index 0069ce530a..b464b7ee7e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -187,6 +187,9 @@ { "path": "packages/opentelemetry-shim-opentracing" }, + { + "path": "packages/platform-common" + }, { "path": "packages/propagator-aws-xray" },