Skip to content

Commit

Permalink
chore(resource-detector-alibaba): use exported strings for attributes
Browse files Browse the repository at this point in the history
Use exported strings for Semantic Resource Attributes, Cloud Platform Values and Cloud Provider Values.

Signed-off-by: maryliag <[email protected]>
  • Loading branch information
maryliag committed Mar 29, 2024
1 parent 85cbc8d commit 3af4c33
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@opentelemetry/resources": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https:/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3af4c33

Please sign in to comment.