Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resources): prevent circular import (resource -> detector -> resource -> ...) #4653

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion packages/opentelemetry-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions packages/opentelemetry-resources/src/detectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetector } from '../../detectors/NoopDetector';
import { noopDetector } from '../../NoopDetector';

export const hostDetector = noopDetector;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetectorSync } from '../../detectors/NoopDetectorSync';
import { noopDetectorSync } from '../../NoopDetectorSync';

export const hostDetectorSync = noopDetectorSync;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetector } from '../../detectors/NoopDetector';
import { noopDetector } from '../../NoopDetector';

export const osDetector = noopDetector;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetectorSync } from '../../detectors/NoopDetectorSync';
import { noopDetectorSync } from '../../NoopDetectorSync';

export const osDetectorSync = noopDetectorSync;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetector } from '../../detectors/NoopDetector';
import { noopDetector } from '../../NoopDetector';

export const processDetector = noopDetector;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

import { noopDetector } from '../../detectors/NoopDetector';
import { noopDetector } from '../../NoopDetector';

export const processDetectorSync = noopDetector;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { noopDetectorSync } from '../../detectors/NoopDetectorSync';
import { noopDetectorSync } from '../../NoopDetectorSync';

/**
* @experimental
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
26 changes: 19 additions & 7 deletions packages/opentelemetry-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion packages/opentelemetry-resources/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './node';
export { defaultServiceName } from './node';
10 changes: 1 addition & 9 deletions packages/opentelemetry-resources/src/platform/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading