From 0a3d4675f4f0ee17ebff3d905869cfe41cc42fc9 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Fri, 26 Apr 2024 14:22:31 +0200 Subject: [PATCH] fix(resources): prevent circular import (resource -> detector -> resource -> ...) (#4653) * fix(resources): prevent circular import (resource -> detector -> resource -> ...) * fixup! fix(resources): prevent circular import (resource -> detector -> resource -> ...) --- CHANGELOG.md | 2 ++ packages/opentelemetry-resources/package.json | 6 ++++- .../src/detectors/BrowserDetector.ts | 10 +++---- .../src/detectors/BrowserDetectorSync.ts | 6 +++-- .../src/detectors/index.ts | 17 +++++++++--- .../platform/browser/HostDetector.ts | 2 +- .../platform/browser/HostDetectorSync.ts | 2 +- .../platform/browser/OSDetector.ts | 2 +- .../platform/browser/OSDetectorSync.ts | 2 +- .../platform/browser/ProcessDetector.ts | 2 +- .../platform/browser/ProcessDetectorSync.ts | 2 +- .../browser/ServiceInstanceIdDetectorSync.ts | 2 +- .../src/detectors/platform/browser/index.ts | 23 ++++++++++++++++ .../src/detectors/platform/index.ts | 24 +++++++++++++++++ .../platform/node/HostDetector.ts | 6 ++--- .../platform/node/HostDetectorSync.ts | 6 ++--- .../platform/node/OSDetector.ts | 6 ++--- .../platform/node/OSDetectorSync.ts | 6 ++--- .../platform/node/ProcessDetector.ts | 6 ++--- .../platform/node/ProcessDetectorSync.ts | 8 +++--- .../node/ServiceInstanceIdDetectorSync.ts | 6 ++--- .../src/detectors/platform/node/index.ts | 23 ++++++++++++++++ .../platform/node/machine-id/execAsync.ts | 0 .../node/machine-id/getMachineId-bsd.ts | 0 .../node/machine-id/getMachineId-darwin.ts | 0 .../node/machine-id/getMachineId-linux.ts | 0 .../machine-id/getMachineId-unsupported.ts | 0 .../node/machine-id/getMachineId-win.ts | 0 .../platform/node/machine-id/getMachineId.ts | 0 .../{ => detectors}/platform/node/utils.ts | 0 packages/opentelemetry-resources/src/index.ts | 26 ++++++++++++++----- .../src/platform/browser/index.ts | 10 +------ .../src/platform/index.ts | 2 +- .../src/platform/node/index.ts | 10 +------ .../test/detectors/node/HostDetector.test.ts | 4 +-- .../node/machine-id/getMachineId-bsd.test.ts | 4 +-- .../machine-id/getMachineId-darwin.test.ts | 4 +-- .../machine-id/getMachineId-linux.test.ts | 2 +- .../node/machine-id/getMachineId-win.test.ts | 4 +-- 39 files changed, 158 insertions(+), 77 deletions(-) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/HostDetector.ts (91%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/HostDetectorSync.ts (90%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/OSDetector.ts (91%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/OSDetectorSync.ts (90%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/ProcessDetector.ts (91%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/ProcessDetectorSync.ts (91%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/browser/ServiceInstanceIdDetectorSync.ts (90%) create mode 100644 packages/opentelemetry-resources/src/detectors/platform/browser/index.ts create mode 100644 packages/opentelemetry-resources/src/detectors/platform/index.ts rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/HostDetector.ts (87%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/HostDetectorSync.ts (90%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/OSDetector.ts (87%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/OSDetectorSync.ts (88%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/ProcessDetector.ts (87%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/ProcessDetectorSync.ts (90%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/ServiceInstanceIdDetectorSync.ts (87%) create mode 100644 packages/opentelemetry-resources/src/detectors/platform/node/index.ts rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/execAsync.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId-bsd.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId-darwin.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId-linux.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId-unsupported.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId-win.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/machine-id/getMachineId.ts (100%) rename packages/opentelemetry-resources/src/{ => detectors}/platform/node/utils.ts (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32875a6c4f..6072f03891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * fix(sdk-trace-web): fix invalid timings in span events [#4486](https://github.com/open-telemetry/opentelemetry-js/pull/4486) @Abinet18 * fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser [#4561](https://github.com/open-telemetry/opentelemetry-js/issues/4561) @trentm +* fix(resources): prevent circular import (resource -> detector -> resource -> ...) [#4653](https://github.com/open-telemetry/opentelemetry-js/pull/4653) @pichlermarc + * fixes a circular import warning which would appear in rollup when bundling `@opentelemetry/resources` ## 1.23.0 diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index d8e48fdfa7..49d87c7a96 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -9,7 +9,11 @@ "./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" + "./build/src/platform/index.js": "./build/src/platform/browser/index.js", + "./src/detectors/platform/index.ts": "./src/detectors/platform/browser/index.ts", + "./build/esm/detectors/platform/index.js": "./build/esm/detectors/platform/browser/index.js", + "./build/esnext/detectors/platform/index.js": "./build/esnext/detectors/platform/browser/index.js", + "./build/src/detectors/platform/index.js": "./build/src/detectors/platform/browser/index.js" }, "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", diff --git a/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts b/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts index e50cd9b50b..d06fc23816 100644 --- a/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/BrowserDetector.ts @@ -14,12 +14,10 @@ * limitations under the License. */ -import { - browserDetectorSync, - Detector, - IResource, - ResourceDetectionConfig, -} from '..'; +import { IResource } from '../IResource'; +import { ResourceDetectionConfig } from '../config'; +import { Detector } from '../types'; +import { browserDetectorSync } from './BrowserDetectorSync'; /** * BrowserDetector will be used to detect the resources related to browser. diff --git a/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts index 66a4801067..c8161198ca 100644 --- a/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts @@ -15,9 +15,11 @@ */ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; -import { DetectorSync, IResource, Resource, ResourceDetectionConfig } from '..'; -import { ResourceAttributes } from '../types'; +import { DetectorSync, ResourceAttributes } from '../types'; import { diag } from '@opentelemetry/api'; +import { ResourceDetectionConfig } from '../config'; +import { IResource } from '../IResource'; +import { Resource } from '../Resource'; /** * BrowserDetectorSync will be used to detect the resources related to browser. diff --git a/packages/opentelemetry-resources/src/detectors/index.ts b/packages/opentelemetry-resources/src/detectors/index.ts index e7d885be6b..74ace665ea 100644 --- a/packages/opentelemetry-resources/src/detectors/index.ts +++ b/packages/opentelemetry-resources/src/detectors/index.ts @@ -14,7 +14,16 @@ * limitations under the License. */ -export * from './BrowserDetector'; -export * from './EnvDetector'; -export * from './BrowserDetectorSync'; -export * from './EnvDetectorSync'; +export { + hostDetector, + hostDetectorSync, + osDetector, + osDetectorSync, + processDetector, + processDetectorSync, + serviceInstanceIdDetectorSync, +} from './platform'; +export { browserDetector } from './BrowserDetector'; +export { envDetector } from './EnvDetector'; +export { browserDetectorSync } from './BrowserDetectorSync'; +export { envDetectorSync } from './EnvDetectorSync'; diff --git a/packages/opentelemetry-resources/src/platform/browser/HostDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/HostDetector.ts similarity index 91% rename from packages/opentelemetry-resources/src/platform/browser/HostDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/HostDetector.ts index e8e4c942c6..b1f022b993 100644 --- a/packages/opentelemetry-resources/src/platform/browser/HostDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/HostDetector.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetector } from '../../detectors/NoopDetector'; +import { noopDetector } from '../../NoopDetector'; export const hostDetector = noopDetector; diff --git a/packages/opentelemetry-resources/src/platform/browser/HostDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/HostDetectorSync.ts similarity index 90% rename from packages/opentelemetry-resources/src/platform/browser/HostDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/HostDetectorSync.ts index 1962f53028..4dc0861dd5 100644 --- a/packages/opentelemetry-resources/src/platform/browser/HostDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/HostDetectorSync.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetectorSync } from '../../detectors/NoopDetectorSync'; +import { noopDetectorSync } from '../../NoopDetectorSync'; export const hostDetectorSync = noopDetectorSync; diff --git a/packages/opentelemetry-resources/src/platform/browser/OSDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/OSDetector.ts similarity index 91% rename from packages/opentelemetry-resources/src/platform/browser/OSDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/OSDetector.ts index 27935fe135..33f6fe4e88 100644 --- a/packages/opentelemetry-resources/src/platform/browser/OSDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/OSDetector.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetector } from '../../detectors/NoopDetector'; +import { noopDetector } from '../../NoopDetector'; export const osDetector = noopDetector; diff --git a/packages/opentelemetry-resources/src/platform/browser/OSDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/OSDetectorSync.ts similarity index 90% rename from packages/opentelemetry-resources/src/platform/browser/OSDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/OSDetectorSync.ts index 416fc3b4ee..490f535bf9 100644 --- a/packages/opentelemetry-resources/src/platform/browser/OSDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/OSDetectorSync.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetectorSync } from '../../detectors/NoopDetectorSync'; +import { noopDetectorSync } from '../../NoopDetectorSync'; export const osDetectorSync = noopDetectorSync; diff --git a/packages/opentelemetry-resources/src/platform/browser/ProcessDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetector.ts similarity index 91% rename from packages/opentelemetry-resources/src/platform/browser/ProcessDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetector.ts index 3d45d1c4fe..200a0940d6 100644 --- a/packages/opentelemetry-resources/src/platform/browser/ProcessDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetector.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetector } from '../../detectors/NoopDetector'; +import { noopDetector } from '../../NoopDetector'; export const processDetector = noopDetector; diff --git a/packages/opentelemetry-resources/src/platform/browser/ProcessDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetectorSync.ts similarity index 91% rename from packages/opentelemetry-resources/src/platform/browser/ProcessDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetectorSync.ts index 6651d30990..df98eddeff 100644 --- a/packages/opentelemetry-resources/src/platform/browser/ProcessDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/ProcessDetectorSync.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -import { noopDetector } from '../../detectors/NoopDetector'; +import { noopDetector } from '../../NoopDetector'; export const processDetectorSync = noopDetector; diff --git a/packages/opentelemetry-resources/src/platform/browser/ServiceInstanceIdDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/ServiceInstanceIdDetectorSync.ts similarity index 90% rename from packages/opentelemetry-resources/src/platform/browser/ServiceInstanceIdDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/browser/ServiceInstanceIdDetectorSync.ts index d79fa1f4ea..5403950a52 100644 --- a/packages/opentelemetry-resources/src/platform/browser/ServiceInstanceIdDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/ServiceInstanceIdDetectorSync.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { noopDetectorSync } from '../../detectors/NoopDetectorSync'; +import { noopDetectorSync } from '../../NoopDetectorSync'; /** * @experimental diff --git a/packages/opentelemetry-resources/src/detectors/platform/browser/index.ts b/packages/opentelemetry-resources/src/detectors/platform/browser/index.ts new file mode 100644 index 0000000000..e8585d7d36 --- /dev/null +++ b/packages/opentelemetry-resources/src/detectors/platform/browser/index.ts @@ -0,0 +1,23 @@ +/* + * 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 { hostDetector } from './HostDetector'; +export { hostDetectorSync } from './HostDetectorSync'; +export { osDetector } from './OSDetector'; +export { osDetectorSync } from './OSDetectorSync'; +export { processDetector } from './ProcessDetector'; +export { processDetectorSync } from './ProcessDetectorSync'; +export { serviceInstanceIdDetectorSync } from './ServiceInstanceIdDetectorSync'; diff --git a/packages/opentelemetry-resources/src/detectors/platform/index.ts b/packages/opentelemetry-resources/src/detectors/platform/index.ts new file mode 100644 index 0000000000..f5393dd7bb --- /dev/null +++ b/packages/opentelemetry-resources/src/detectors/platform/index.ts @@ -0,0 +1,24 @@ +/* + * 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 { + hostDetector, + hostDetectorSync, + osDetector, + osDetectorSync, + processDetector, + processDetectorSync, + serviceInstanceIdDetectorSync, +} from './node'; diff --git a/packages/opentelemetry-resources/src/platform/node/HostDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/node/HostDetector.ts similarity index 87% rename from packages/opentelemetry-resources/src/platform/node/HostDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/HostDetector.ts index daf0b8e045..fe95b3d89d 100644 --- a/packages/opentelemetry-resources/src/platform/node/HostDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/HostDetector.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { Detector } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; -import { IResource } from '../../IResource'; +import { Detector } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; +import { IResource } from '../../../IResource'; import { hostDetectorSync } from './HostDetectorSync'; /** diff --git a/packages/opentelemetry-resources/src/platform/node/HostDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/node/HostDetectorSync.ts similarity index 90% rename from packages/opentelemetry-resources/src/platform/node/HostDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/HostDetectorSync.ts index 9bd5e6cb5f..ec00a90105 100644 --- a/packages/opentelemetry-resources/src/platform/node/HostDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/HostDetectorSync.ts @@ -15,9 +15,9 @@ */ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; -import { Resource } from '../../Resource'; -import { DetectorSync, ResourceAttributes } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; +import { Resource } from '../../../Resource'; +import { DetectorSync, ResourceAttributes } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; import { arch, hostname } from 'os'; import { normalizeArch } from './utils'; import { getMachineId } from './machine-id/getMachineId'; diff --git a/packages/opentelemetry-resources/src/platform/node/OSDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts similarity index 87% rename from packages/opentelemetry-resources/src/platform/node/OSDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts index 7ee528d497..b8720d293a 100644 --- a/packages/opentelemetry-resources/src/platform/node/OSDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { Detector } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; -import { IResource } from '../../IResource'; +import { Detector } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; +import { IResource } from '../../../IResource'; import { osDetectorSync } from './OSDetectorSync'; /** diff --git a/packages/opentelemetry-resources/src/platform/node/OSDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/node/OSDetectorSync.ts similarity index 88% rename from packages/opentelemetry-resources/src/platform/node/OSDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/OSDetectorSync.ts index 9cb6a0385d..3acee890f4 100644 --- a/packages/opentelemetry-resources/src/platform/node/OSDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/OSDetectorSync.ts @@ -15,9 +15,9 @@ */ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; -import { Resource } from '../../Resource'; -import { DetectorSync, ResourceAttributes } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; +import { Resource } from '../../../Resource'; +import { DetectorSync, ResourceAttributes } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; import { platform, release } from 'os'; import { normalizeType } from './utils'; diff --git a/packages/opentelemetry-resources/src/platform/node/ProcessDetector.ts b/packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetector.ts similarity index 87% rename from packages/opentelemetry-resources/src/platform/node/ProcessDetector.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetector.ts index 20345e6af9..13b31a34ee 100644 --- a/packages/opentelemetry-resources/src/platform/node/ProcessDetector.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetector.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { Detector } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; -import { IResource } from '../../IResource'; +import { Detector } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; +import { IResource } from '../../../IResource'; import { processDetectorSync } from './ProcessDetectorSync'; /** diff --git a/packages/opentelemetry-resources/src/platform/node/ProcessDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetectorSync.ts similarity index 90% rename from packages/opentelemetry-resources/src/platform/node/ProcessDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetectorSync.ts index 4cad06a458..087d3f914f 100644 --- a/packages/opentelemetry-resources/src/platform/node/ProcessDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetectorSync.ts @@ -16,10 +16,10 @@ import { diag } from '@opentelemetry/api'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; -import { Resource } from '../../Resource'; -import { DetectorSync, ResourceAttributes } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; -import { IResource } from '../../IResource'; +import { Resource } from '../../../Resource'; +import { DetectorSync, ResourceAttributes } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; +import { IResource } from '../../../IResource'; import * as os from 'os'; /** diff --git a/packages/opentelemetry-resources/src/platform/node/ServiceInstanceIdDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/platform/node/ServiceInstanceIdDetectorSync.ts similarity index 87% rename from packages/opentelemetry-resources/src/platform/node/ServiceInstanceIdDetectorSync.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/ServiceInstanceIdDetectorSync.ts index 9196bcba51..7c0afae59e 100644 --- a/packages/opentelemetry-resources/src/platform/node/ServiceInstanceIdDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/platform/node/ServiceInstanceIdDetectorSync.ts @@ -15,9 +15,9 @@ */ import { SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions'; -import { Resource } from '../../Resource'; -import { DetectorSync, ResourceAttributes } from '../../types'; -import { ResourceDetectionConfig } from '../../config'; +import { Resource } from '../../../Resource'; +import { DetectorSync, ResourceAttributes } from '../../../types'; +import { ResourceDetectionConfig } from '../../../config'; import { randomUUID } from 'crypto'; /** diff --git a/packages/opentelemetry-resources/src/detectors/platform/node/index.ts b/packages/opentelemetry-resources/src/detectors/platform/node/index.ts new file mode 100644 index 0000000000..e8585d7d36 --- /dev/null +++ b/packages/opentelemetry-resources/src/detectors/platform/node/index.ts @@ -0,0 +1,23 @@ +/* + * 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 { hostDetector } from './HostDetector'; +export { hostDetectorSync } from './HostDetectorSync'; +export { osDetector } from './OSDetector'; +export { osDetectorSync } from './OSDetectorSync'; +export { processDetector } from './ProcessDetector'; +export { processDetectorSync } from './ProcessDetectorSync'; +export { serviceInstanceIdDetectorSync } from './ServiceInstanceIdDetectorSync'; diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/execAsync.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/execAsync.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/execAsync.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/execAsync.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-bsd.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-bsd.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-bsd.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-bsd.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-darwin.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-darwin.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-darwin.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-darwin.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-linux.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-linux.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-linux.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-linux.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-unsupported.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-unsupported.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-unsupported.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-unsupported.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-win.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-win.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId-win.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId-win.ts diff --git a/packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId.ts b/packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/machine-id/getMachineId.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/machine-id/getMachineId.ts diff --git a/packages/opentelemetry-resources/src/platform/node/utils.ts b/packages/opentelemetry-resources/src/detectors/platform/node/utils.ts similarity index 100% rename from packages/opentelemetry-resources/src/platform/node/utils.ts rename to packages/opentelemetry-resources/src/detectors/platform/node/utils.ts diff --git a/packages/opentelemetry-resources/src/index.ts b/packages/opentelemetry-resources/src/index.ts index 3f66901fbb..2162658c3d 100644 --- a/packages/opentelemetry-resources/src/index.ts +++ b/packages/opentelemetry-resources/src/index.ts @@ -14,10 +14,22 @@ * limitations under the License. */ -export * from './Resource'; -export * from './IResource'; -export * from './platform'; -export * from './types'; -export * from './config'; -export * from './detectors'; -export * from './detect-resources'; +export { Resource } from './Resource'; +export { IResource } from './IResource'; +export { defaultServiceName } from './platform'; +export { DetectorSync, ResourceAttributes, Detector } from './types'; +export { ResourceDetectionConfig } from './config'; +export { + browserDetector, + browserDetectorSync, + envDetector, + envDetectorSync, + hostDetector, + hostDetectorSync, + osDetector, + osDetectorSync, + processDetector, + processDetectorSync, + serviceInstanceIdDetectorSync, +} from './detectors'; +export { detectResourcesSync, detectResources } from './detect-resources'; diff --git a/packages/opentelemetry-resources/src/platform/browser/index.ts b/packages/opentelemetry-resources/src/platform/browser/index.ts index 18a221b550..7d7c361648 100644 --- a/packages/opentelemetry-resources/src/platform/browser/index.ts +++ b/packages/opentelemetry-resources/src/platform/browser/index.ts @@ -13,12 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -export * from './default-service-name'; -export * from './HostDetector'; -export * from './HostDetectorSync'; -export * from './OSDetector'; -export * from './OSDetectorSync'; -export * from './ProcessDetector'; -export * from './ProcessDetectorSync'; -export * from './ServiceInstanceIdDetectorSync'; +export { defaultServiceName } from './default-service-name'; diff --git a/packages/opentelemetry-resources/src/platform/index.ts b/packages/opentelemetry-resources/src/platform/index.ts index cdaf8858ce..ac520108f4 100644 --- a/packages/opentelemetry-resources/src/platform/index.ts +++ b/packages/opentelemetry-resources/src/platform/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './node'; +export { defaultServiceName } from './node'; diff --git a/packages/opentelemetry-resources/src/platform/node/index.ts b/packages/opentelemetry-resources/src/platform/node/index.ts index 18a221b550..7d7c361648 100644 --- a/packages/opentelemetry-resources/src/platform/node/index.ts +++ b/packages/opentelemetry-resources/src/platform/node/index.ts @@ -13,12 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -export * from './default-service-name'; -export * from './HostDetector'; -export * from './HostDetectorSync'; -export * from './OSDetector'; -export * from './OSDetectorSync'; -export * from './ProcessDetector'; -export * from './ProcessDetectorSync'; -export * from './ServiceInstanceIdDetectorSync'; +export { defaultServiceName } from './default-service-name'; diff --git a/packages/opentelemetry-resources/test/detectors/node/HostDetector.test.ts b/packages/opentelemetry-resources/test/detectors/node/HostDetector.test.ts index 2e69de7e19..ecf4d04a59 100644 --- a/packages/opentelemetry-resources/test/detectors/node/HostDetector.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/HostDetector.test.ts @@ -27,7 +27,7 @@ describeNode('hostDetector() on Node.js', () => { it('should return resource information about the host', async () => { const os = require('os'); - const mid = require('../../../src/platform/node/machine-id/getMachineId'); + const mid = require('../../../src/detectors/platform/node/machine-id/getMachineId'); const expectedHostId = 'f2c668b579780554f70f72a063dc0864'; @@ -67,7 +67,7 @@ describeNode('hostDetector() on Node.js', () => { it('should handle missing machine id', async () => { const os = require('os'); - const mid = require('../../../src/platform/node/machine-id/getMachineId'); + const mid = require('../../../src/detectors/platform/node/machine-id/getMachineId'); sinon.stub(os, 'arch').returns('x64'); sinon.stub(os, 'hostname').returns('opentelemetry-test'); diff --git a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-bsd.test.ts b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-bsd.test.ts index ba60b1a944..6018055ddd 100644 --- a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-bsd.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-bsd.test.ts @@ -18,8 +18,8 @@ import * as sinon from 'sinon'; import * as assert from 'assert'; import { promises as fs } from 'fs'; import { PromiseWithChild } from 'child_process'; -import * as util from '../../../../src/platform/node/machine-id/execAsync'; -import { getMachineId } from '../../../../src/platform/node/machine-id/getMachineId-bsd'; +import * as util from '../../../../src/detectors/platform/node/machine-id/execAsync'; +import { getMachineId } from '../../../../src/detectors/platform/node/machine-id/getMachineId-bsd'; describe('getMachineId on BSD', () => { const expectedMachineId = 'f2c668b579780554f70f72a063dc0864'; diff --git a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-darwin.test.ts b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-darwin.test.ts index 06e1f942f8..8f9c748851 100644 --- a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-darwin.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-darwin.test.ts @@ -17,8 +17,8 @@ import * as sinon from 'sinon'; import * as assert from 'assert'; import { PromiseWithChild } from 'child_process'; -import * as util from '../../../../src/platform/node/machine-id/execAsync'; -import { getMachineId } from '../../../../src/platform/node/machine-id/getMachineId-darwin'; +import * as util from '../../../../src/detectors/platform/node/machine-id/execAsync'; +import { getMachineId } from '../../../../src/detectors/platform/node/machine-id/getMachineId-darwin'; describe('getMachineId on Darwin', () => { const expectedMachineId = '81895B8D-9EF9-4EBB-B5DE-B00069CF53F0'; diff --git a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-linux.test.ts b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-linux.test.ts index 41526db379..a9cd6e204f 100644 --- a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-linux.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-linux.test.ts @@ -18,7 +18,7 @@ import * as sinon from 'sinon'; import * as assert from 'assert'; import { promises as fs } from 'fs'; -import { getMachineId } from '../../../../src/platform/node/machine-id/getMachineId-linux'; +import { getMachineId } from '../../../../src/detectors/platform/node/machine-id/getMachineId-linux'; describe('getMachineId on linux', () => { const expectedMachineId = 'f2c668b579780554f70f72a063dc0864'; diff --git a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-win.test.ts b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-win.test.ts index fba7747fee..ff8c8713f1 100644 --- a/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-win.test.ts +++ b/packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-win.test.ts @@ -17,8 +17,8 @@ import * as sinon from 'sinon'; import * as assert from 'assert'; import { PromiseWithChild } from 'child_process'; -import * as util from '../../../../src/platform/node/machine-id/execAsync'; -import { getMachineId } from '../../../../src/platform/node/machine-id/getMachineId-win'; +import * as util from '../../../../src/detectors/platform/node/machine-id/execAsync'; +import { getMachineId } from '../../../../src/detectors/platform/node/machine-id/getMachineId-win'; describe('getMachineId on Windows', () => { const expectedMachineId = 'fe11b90a-d48c-4c3b-b386-e40cc383fd30';