diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cd26659814..3d94358c94e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se * chore!: Raise the minimum supported Node.js version to `^18.19.0 || >=20.6.0`. Support for Node.js 14, 16, and early minor versions of 18 and 20 have been dropped. This applies to all packages except the 'api' and 'semantic-conventions' packages. [#5395](https://github.com/open-telemetry/opentelemetry-js/issues/5395) @trentm * feat(core)!: remove TracesSamplerValues from exports [#5406](https://github.com/open-telemetry/opentelemetry-js/pull/5406) @pichlermarc * (user-facing): TracesSamplerValues was only consumed internally and has been removed from exports without replacement +* chore(resources)!: Remove deprecated duplicate browser detector from `@opentelemetry/resource` in favor of `@opentelemetry/opentelemetry-browser-detector` [#5420](https://github.com/open-telemetry/opentelemetry-js/pull/5420) * feat(core)!: remove unused and obsolete functions and types [#5444](https://github.com/open-telemetry/opentelemetry-js/pull/5444) @pichlermarc * (user-facing): `VERSION` was an internal constant that was unintentionally exported. It has been removed without replacement. * (user-facing): `isWrapped` has been removed in favor of `isWrapped` from `@opentelemetry/instrumentation` diff --git a/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts b/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts deleted file mode 100644 index 984b08e5b75..00000000000 --- a/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts +++ /dev/null @@ -1,70 +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. - */ - -import { Attributes, diag } from '@opentelemetry/api'; -import { - SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION, - SEMRESATTRS_PROCESS_RUNTIME_NAME, - SEMRESATTRS_PROCESS_RUNTIME_VERSION, -} from '@opentelemetry/semantic-conventions'; -import { ResourceDetectionConfig } from '../config'; -import { DetectedResource, ResourceDetector } from '../types'; - -/** - * BrowserDetector will be used to detect the resources related to browser. - */ -class BrowserDetector implements ResourceDetector { - detect(config?: ResourceDetectionConfig): DetectedResource { - const isBrowser = - typeof navigator !== 'undefined' && - global.process?.versions?.node === undefined && // Node.js v21 adds `navigator` - // @ts-expect-error don't have Bun types - global.Bun?.version === undefined; // Bun (bun.sh) defines `navigator` - if (!isBrowser) { - return { attributes: {} }; - } - const browserResource: Attributes = { - [SEMRESATTRS_PROCESS_RUNTIME_NAME]: 'browser', - [SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION]: 'Web Browser', - [SEMRESATTRS_PROCESS_RUNTIME_VERSION]: navigator.userAgent, - }; - return this._getResourceAttributes(browserResource, config); - } - /** - * Validates process resource attribute map from process variables - * - * @param browserResource The un-sanitized resource attributes from process as key/value pairs. - * @param config: Config - * @returns The sanitized resource attributes. - */ - private _getResourceAttributes( - browserResource: Attributes, - _config?: ResourceDetectionConfig - ) { - if (browserResource[SEMRESATTRS_PROCESS_RUNTIME_VERSION] === '') { - diag.debug( - 'BrowserDetector failed: Unable to find required browser resources. ' - ); - return { attributes: {} }; - } else { - return { - attributes: browserResource, - }; - } - } -} - -export const browserDetector = new BrowserDetector(); diff --git a/packages/opentelemetry-resources/src/detectors/index.ts b/packages/opentelemetry-resources/src/detectors/index.ts index 8fac0e3574b..eaaabb7dae4 100644 --- a/packages/opentelemetry-resources/src/detectors/index.ts +++ b/packages/opentelemetry-resources/src/detectors/index.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -export { browserDetector } from './BrowserDetector'; export { envDetector } from './EnvDetector'; export { hostDetector, diff --git a/packages/opentelemetry-resources/src/index.ts b/packages/opentelemetry-resources/src/index.ts index 754549ba5c9..812bda333ee 100644 --- a/packages/opentelemetry-resources/src/index.ts +++ b/packages/opentelemetry-resources/src/index.ts @@ -17,7 +17,6 @@ export { ResourceDetectionConfig } from './config'; export { detectResources } from './detect-resources'; export { - browserDetector, envDetector, hostDetector, osDetector, diff --git a/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts b/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts deleted file mode 100644 index 59d298f98d4..00000000000 --- a/packages/opentelemetry-resources/test/detectors/browser/BrowserDetector.test.ts +++ /dev/null @@ -1,48 +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. - */ -import * as sinon from 'sinon'; -import { browserDetector } from '../../../src/detectors/BrowserDetector'; -import { describeBrowser } from '../../util'; -import { - assertEmptyResource, - assertResource, -} from '../../util/resource-assertions'; - -describeBrowser('browserDetector()', () => { - afterEach(() => { - sinon.restore(); - }); - - it('should return browser information', async () => { - sinon.stub(globalThis, 'navigator').value({ - userAgent: 'dddd', - }); - - const resource = browserDetector.detect(); - assertResource(resource, { - version: 'dddd', - runtimeDescription: 'Web Browser', - runtimeName: 'browser', - }); - }); - it('should return empty resources if version is missing', async () => { - sinon.stub(globalThis, 'navigator').value({ - userAgent: '', - }); - const resource = browserDetector.detect(); - assertEmptyResource(resource); - }); -}); diff --git a/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts b/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts deleted file mode 100644 index 159dd02c2e5..00000000000 --- a/packages/opentelemetry-resources/test/detectors/node/BrowserDetector.test.ts +++ /dev/null @@ -1,26 +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. - */ -import { Resource } from '../../../src'; -import { browserDetector } from '../../../src/detectors/BrowserDetector'; -import { describeNode } from '../../util'; -import { assertEmptyResource } from '../../util/resource-assertions'; - -describeNode('browserDetector()', () => { - it('should return empty resources if window.document is missing', async () => { - const resource = new Resource(browserDetector.detect()); - assertEmptyResource(resource); - }); -});