Skip to content

Commit c6f9a6c

Browse files
committed
Merge remote-tracking branch 'upstream/main' into kafkajs-tav-file
2 parents ed21e0d + 7fb4ba3 commit c6f9a6c

File tree

181 files changed

+3251
-5703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3251
-5703
lines changed

.github/workflows/test-all-versions.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
strategy:
4747
fail-fast: false
4848
matrix:
49-
node: ["14", "16", "18", "20", "22"]
49+
node: ["18", "20", "22"]
5050
runs-on: ubuntu-latest
5151
services:
5252
mongo:
@@ -143,9 +143,6 @@ jobs:
143143
node-version: ${{ matrix.node }}
144144
- name: Set MySQL variables
145145
run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} -e "SET GLOBAL log_output='TABLE'; SET GLOBAL general_log = 1;" mysql
146-
- name: Update npm to a version that supports workspaces (v7 or later)
147-
if: ${{ matrix.node < 16 }}
148-
run: npm install -g npm@9 # npm@9 supports node >=14.17.0
149146
- name: Install
150147
run: npm ci
151148
- name: Download Build Artifacts

.github/workflows/unit-test.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
node: ["14", "16", "18", "20", "22"]
40+
node:
41+
- "18.19.0"
42+
- "18"
43+
- "20.6.0"
44+
- "20"
45+
- "22"
4146
include:
4247
- node: 18
4348
code-coverage: true
@@ -151,9 +156,6 @@ jobs:
151156
node-version: ${{ matrix.node }}
152157
- name: Set MySQL variables
153158
run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} -e "SET GLOBAL log_output='TABLE'; SET GLOBAL general_log = 1;" mysql
154-
- name: Update npm to a version that supports workspaces (v7 or later)
155-
if: ${{ matrix.node < 16 }}
156-
run: npm install -g npm@9 # npm@9 supports node >=14.17.0
157159
- name: Install
158160
run: npm ci
159161
- name: Download Build Artifacts

detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"author": "OpenTelemetry Authors",
2929
"license": "Apache-2.0",
3030
"engines": {
31-
"node": ">=14"
31+
"node": "^18.19.0 || >=20.6.0"
3232
},
3333
"files": [
3434
"build/src/**/*.js",
@@ -44,21 +44,22 @@
4444
"devDependencies": {
4545
"@opentelemetry/api": "^1.0.0",
4646
"@opentelemetry/contrib-test-utils": "^0.45.1",
47+
"@opentelemetry/sdk-trace-base": "^2.0.0",
4748
"@types/mocha": "10.0.10",
4849
"@types/node": "18.18.14",
4950
"@types/sinon": "17.0.4",
5051
"nock": "13.3.3",
5152
"nyc": "15.1.0",
5253
"rimraf": "5.0.10",
5354
"sinon": "15.2.0",
54-
"typescript": "4.4.4"
55+
"typescript": "5.0.4"
5556
},
5657
"peerDependencies": {
5758
"@opentelemetry/api": "^1.0.0"
5859
},
5960
"dependencies": {
60-
"@opentelemetry/core": "^1.26.0",
61-
"@opentelemetry/resources": "^1.10.0",
61+
"@opentelemetry/core": "^2.0.0",
62+
"@opentelemetry/resources": "^2.0.0",
6263
"@opentelemetry/semantic-conventions": "^1.27.0"
6364
},
6465
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme",

detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { context } from '@opentelemetry/api';
17+
import { context, diag } from '@opentelemetry/api';
1818
import { suppressTracing } from '@opentelemetry/core';
1919
import {
20-
DetectorSync,
21-
IResource,
22-
Resource,
23-
ResourceAttributes,
24-
ResourceDetectionConfig,
20+
ResourceDetector,
21+
DetectedResource,
22+
DetectedResourceAttributes,
2523
} from '@opentelemetry/resources';
2624
import {
2725
CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
@@ -43,7 +41,7 @@ import * as http from 'http';
4341
* AlibabaCloud ECS and return a {@link Resource} populated with metadata about
4442
* the ECS instance. Returns an empty Resource if detection fails.
4543
*/
46-
class AlibabaCloudEcsDetector implements DetectorSync {
44+
class AlibabaCloudEcsDetector implements ResourceDetector {
4745
/**
4846
* See https://www.alibabacloud.com/help/doc-detail/67254.htm for
4947
* documentation about the AlibabaCloud instance identity document.
@@ -62,36 +60,59 @@ class AlibabaCloudEcsDetector implements DetectorSync {
6260
*
6361
* @param config (unused) The resource detection config
6462
*/
65-
detect(_config?: ResourceDetectionConfig): IResource {
66-
const attributes = context.with(suppressTracing(context.active()), () =>
67-
this._getAttributes()
63+
detect(): DetectedResource {
64+
const dataPromise = context.with(suppressTracing(context.active()), () =>
65+
this._gatherData()
6866
);
69-
return new Resource({}, attributes);
67+
68+
const attrNames = [
69+
SEMRESATTRS_CLOUD_PROVIDER,
70+
SEMRESATTRS_CLOUD_PLATFORM,
71+
SEMRESATTRS_CLOUD_ACCOUNT_ID,
72+
SEMRESATTRS_CLOUD_REGION,
73+
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
74+
SEMRESATTRS_HOST_ID,
75+
SEMRESATTRS_HOST_TYPE,
76+
SEMRESATTRS_HOST_NAME,
77+
];
78+
79+
const attributes = {} as DetectedResourceAttributes;
80+
attrNames.forEach(name => {
81+
// Each resource attribute is determined asynchronously in _gatherData().
82+
attributes[name] = dataPromise.then(data => data[name]);
83+
});
84+
85+
return { attributes };
7086
}
7187

7288
/** Gets identity and host info and returns them as attribs. Empty object if fails */
73-
async _getAttributes(
74-
_config?: ResourceDetectionConfig
75-
): Promise<ResourceAttributes> {
76-
const {
77-
'owner-account-id': accountId,
78-
'instance-id': instanceId,
79-
'instance-type': instanceType,
80-
'region-id': region,
81-
'zone-id': availabilityZone,
82-
} = await this._fetchIdentity();
83-
const hostname = await this._fetchHost();
89+
async _gatherData(): Promise<DetectedResourceAttributes> {
90+
try {
91+
const {
92+
'owner-account-id': accountId,
93+
'instance-id': instanceId,
94+
'instance-type': instanceType,
95+
'region-id': region,
96+
'zone-id': availabilityZone,
97+
} = await this._fetchIdentity();
98+
const hostname = await this._fetchHost();
8499

85-
return {
86-
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
87-
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
88-
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
89-
[SEMRESATTRS_CLOUD_REGION]: region,
90-
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
91-
[SEMRESATTRS_HOST_ID]: instanceId,
92-
[SEMRESATTRS_HOST_TYPE]: instanceType,
93-
[SEMRESATTRS_HOST_NAME]: hostname,
94-
};
100+
return {
101+
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
102+
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
103+
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
104+
[SEMRESATTRS_CLOUD_REGION]: region,
105+
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
106+
[SEMRESATTRS_HOST_ID]: instanceId,
107+
[SEMRESATTRS_HOST_TYPE]: instanceType,
108+
[SEMRESATTRS_HOST_NAME]: hostname,
109+
};
110+
} catch (err: any) {
111+
diag.debug(
112+
`${this.constructor.name}: did not detect resource: ${err?.message}`
113+
);
114+
return {};
115+
}
95116
}
96117

97118
/**

detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { setTimeout as setTimeoutP } from 'timers/promises';
1718
import * as nock from 'nock';
1819
import * as assert from 'assert';
19-
import { Resource } from '@opentelemetry/resources';
20+
import { detectResources } from '@opentelemetry/resources';
2021
import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions';
2122
import {
2223
assertCloudResource,
@@ -63,7 +64,9 @@ describe('alibabaCloudEcsDetector', () => {
6364
.get(ALIYUN_HOST_PATH)
6465
.reply(200, () => mockedHostResponse);
6566

66-
const resource: Resource = await alibabaCloudEcsDetector.detect();
67+
const resource = detectResources({
68+
detectors: [alibabaCloudEcsDetector],
69+
});
6770
await resource.waitForAsyncAttributes?.();
6871

6972
scope.done();
@@ -93,7 +96,9 @@ describe('alibabaCloudEcsDetector', () => {
9396
.get(ALIYUN_HOST_PATH)
9497
.reply(404, () => new Error());
9598

96-
const resource = await alibabaCloudEcsDetector.detect();
99+
const resource = detectResources({
100+
detectors: [alibabaCloudEcsDetector],
101+
});
97102
await resource.waitForAsyncAttributes?.();
98103

99104
assert.deepStrictEqual(resource.attributes, {});
@@ -109,7 +114,9 @@ describe('alibabaCloudEcsDetector', () => {
109114
.delayConnection(2000)
110115
.reply(200, () => mockedHostResponse);
111116

112-
const resource = await alibabaCloudEcsDetector.detect();
117+
const resource = detectResources({
118+
detectors: [alibabaCloudEcsDetector],
119+
});
113120
await resource.waitForAsyncAttributes?.();
114121

115122
assert.deepStrictEqual(resource.attributes, {});
@@ -122,10 +129,46 @@ describe('alibabaCloudEcsDetector', () => {
122129
.get(ALIYUN_IDENTITY_PATH)
123130
.replyWithError('NOT FOUND');
124131

125-
const resource = await alibabaCloudEcsDetector.detect();
132+
const resource = detectResources({
133+
detectors: [alibabaCloudEcsDetector],
134+
});
135+
await resource.waitForAsyncAttributes?.();
136+
137+
assert.deepStrictEqual(resource.attributes, {});
138+
139+
scope.done();
140+
});
141+
});
142+
143+
describe('with delay in calling .waitForAsyncAttributes()', () => {
144+
// Note any `unhandledRejection` process events during the test run.
145+
let gotUnhandledRejections: Error[];
146+
const unhandleRejectionHandler = (err: any) => {
147+
gotUnhandledRejections.push(err);
148+
};
149+
beforeEach(() => {
150+
gotUnhandledRejections = [];
151+
process.on('unhandledRejection', unhandleRejectionHandler);
152+
});
153+
afterEach(() => {
154+
process.removeListener('unhandledRejection', unhandleRejectionHandler);
155+
});
156+
157+
it('should return empty resource when receiving error', async () => {
158+
const scope = nock(ALIYUN_HOST)
159+
.get(ALIYUN_IDENTITY_PATH)
160+
.replyWithError('NOT FOUND');
161+
162+
const resource = detectResources({
163+
detectors: [alibabaCloudEcsDetector],
164+
});
165+
// This pause simulates the delay between `detectResources` and
166+
// `waitForAsyncAttributes` typically called later in an exporter.
167+
await setTimeoutP(200); // Hope this is enough time to get error response.
126168
await resource.waitForAsyncAttributes?.();
127169

128170
assert.deepStrictEqual(resource.attributes, {});
171+
assert.deepStrictEqual(gotUnhandledRejections, []);
129172

130173
scope.done();
131174
});

detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetectorIntegration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
SimpleSpanProcessor,
2323
} from '@opentelemetry/sdk-trace-base';
2424
import { NodeSDK } from '@opentelemetry/sdk-node';
25-
import { IResource } from '@opentelemetry/resources';
25+
import { detectResources } from '@opentelemetry/resources';
2626

2727
describe('[Integration] AlibabaCloudEcsDetector', () => {
2828
it('should not start spans for detector requests', async () => {
@@ -47,7 +47,7 @@ describe('[Integration] AlibabaCloudEcsDetector', () => {
4747
const {
4848
alibabaCloudEcsDetector,
4949
} = require('../../build/src/detectors/AlibabaCloudEcsDetector');
50-
const resource = alibabaCloudEcsDetector.detect() as IResource;
50+
const resource = detectResources({ detectors: [alibabaCloudEcsDetector] });
5151
await resource.waitForAsyncAttributes?.();
5252

5353
// Wait for the next loop to let the span close properly

detectors/node/opentelemetry-resource-detector-aws/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"author": "OpenTelemetry Authors",
2828
"license": "Apache-2.0",
2929
"engines": {
30-
"node": ">=14"
30+
"node": "^18.19.0 || >=20.6.0"
3131
},
3232
"files": [
3333
"build/src/**/*.js",
@@ -44,22 +44,23 @@
4444
"@opentelemetry/api": "^1.0.0",
4545
"@opentelemetry/contrib-test-utils": "^0.45.1",
4646
"@opentelemetry/instrumentation-fs": "^0.19.1",
47-
"@opentelemetry/instrumentation-http": "^0.57.2",
47+
"@opentelemetry/instrumentation-http": "^0.200.0",
48+
"@opentelemetry/sdk-trace-base": "^2.0.0",
4849
"@types/mocha": "10.0.10",
4950
"@types/node": "18.18.14",
5051
"@types/sinon": "17.0.4",
5152
"nock": "13.3.3",
5253
"nyc": "15.1.0",
5354
"rimraf": "5.0.10",
5455
"sinon": "15.2.0",
55-
"typescript": "4.4.4"
56+
"typescript": "5.0.4"
5657
},
5758
"peerDependencies": {
5859
"@opentelemetry/api": "^1.0.0"
5960
},
6061
"dependencies": {
61-
"@opentelemetry/core": "^1.0.0",
62-
"@opentelemetry/resources": "^1.10.0",
62+
"@opentelemetry/core": "^2.0.0",
63+
"@opentelemetry/resources": "^2.0.0",
6364
"@opentelemetry/semantic-conventions": "^1.27.0"
6465
},
6566
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-aws#readme",

0 commit comments

Comments
 (0)