From ab344a833d2226d48fd10a2244d86a864be00478 Mon Sep 17 00:00:00 2001 From: maryliag Date: Wed, 27 Mar 2024 10:22:59 -0400 Subject: [PATCH] chore(resource-detector-alibaba): use exported strings for attributes Use exported strings for Semantic Resource Attributes, Cloud Platform Values and Cloud Provider Values. Signed-off-by: maryliag --- .../package.json | 2 +- .../src/detectors/AlibabaCloudEcsDetector.ts | 31 +++++++++++-------- .../detectors/AlibabaCloudEcsDetector.test.ts | 4 +-- package-lock.json | 4 +-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json index 68162e3f2f..5009697401 100644 --- a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json +++ b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/package.json @@ -57,7 +57,7 @@ }, "dependencies": { "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme" } diff --git a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts index 38e54df5ba..776e5dbccd 100644 --- a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts @@ -20,9 +20,16 @@ import { ResourceDetectionConfig, } from '@opentelemetry/resources'; import { - CloudPlatformValues, - CloudProviderValues, - SemanticResourceAttributes, + CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS, + CLOUDPROVIDERVALUES_ALIBABA_CLOUD, + SEMRESATTRS_CLOUD_ACCOUNT_ID, + SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, + SEMRESATTRS_CLOUD_PLATFORM, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CLOUD_REGION, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_HOST_NAME, + SEMRESATTRS_HOST_TYPE, } from '@opentelemetry/semantic-conventions'; import * as http from 'http'; @@ -61,16 +68,14 @@ class AlibabaCloudEcsDetector implements Detector { const hostname = await this._fetchHost(); return new Resource({ - [SemanticResourceAttributes.CLOUD_PROVIDER]: - CloudProviderValues.ALIBABA_CLOUD, - [SemanticResourceAttributes.CLOUD_PLATFORM]: - CloudPlatformValues.ALIBABA_CLOUD_ECS, - [SemanticResourceAttributes.CLOUD_ACCOUNT_ID]: accountId, - [SemanticResourceAttributes.CLOUD_REGION]: region, - [SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE]: availabilityZone, - [SemanticResourceAttributes.HOST_ID]: instanceId, - [SemanticResourceAttributes.HOST_TYPE]: instanceType, - [SemanticResourceAttributes.HOST_NAME]: hostname, + [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD, + [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS, + [SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId, + [SEMRESATTRS_CLOUD_REGION]: region, + [SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone, + [SEMRESATTRS_HOST_ID]: instanceId, + [SEMRESATTRS_HOST_TYPE]: instanceType, + [SEMRESATTRS_HOST_NAME]: hostname, }); } diff --git a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts index 14fa8ac1f4..c4a2c41d36 100644 --- a/detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts @@ -17,7 +17,7 @@ import * as nock from 'nock'; import * as assert from 'assert'; import { Resource } from '@opentelemetry/resources'; -import { CloudProviderValues } from '@opentelemetry/semantic-conventions'; +import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions'; import { alibabaCloudEcsDetector } from '../../src'; import { assertCloudResource, @@ -70,7 +70,7 @@ describe('alibabaCloudEcsDetector', () => { assert.ok(resource); assertCloudResource(resource, { - provider: CloudProviderValues.ALIBABA_CLOUD, + provider: CLOUDPROVIDERVALUES_ALIBABA_CLOUD, accountId: 'my-owner-account-id', region: 'my-region-id', zone: 'my-zone-id', diff --git a/package-lock.json b/package-lock.json index 66b5c5382d..838df34c34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.0.0", @@ -47597,7 +47597,7 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/contrib-test-utils": "^0.37.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/sinon": "10.0.18",