Skip to content

Commit 2fd905e

Browse files
authored
chore(resource-detector-alibaba-cloud): update semconv usage to ATTR_ exports (#3051)
Refs: #2377
1 parent ff6f928 commit 2fd905e

File tree

5 files changed

+147
-34
lines changed

5 files changed

+147
-34
lines changed

package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/resource-detector-alibaba-cloud/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@opentelemetry/core": "^2.0.0",
66-
"@opentelemetry/resources": "^2.0.0",
67-
"@opentelemetry/semantic-conventions": "^1.27.0"
66+
"@opentelemetry/resources": "^2.0.0"
6867
},
6968
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/resource-detector-alibaba-cloud#readme",
7069
"sideEffects": false

packages/resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ import {
2222
DetectedResourceAttributes,
2323
} from '@opentelemetry/resources';
2424
import {
25-
CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
26-
CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
27-
SEMRESATTRS_CLOUD_ACCOUNT_ID,
28-
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
29-
SEMRESATTRS_CLOUD_PLATFORM,
30-
SEMRESATTRS_CLOUD_PROVIDER,
31-
SEMRESATTRS_CLOUD_REGION,
32-
SEMRESATTRS_HOST_ID,
33-
SEMRESATTRS_HOST_NAME,
34-
SEMRESATTRS_HOST_TYPE,
35-
} from '@opentelemetry/semantic-conventions';
25+
CLOUD_PLATFORM_VALUE_ALIBABA_CLOUD_ECS,
26+
CLOUD_PROVIDER_VALUE_ALIBABA_CLOUD,
27+
ATTR_CLOUD_ACCOUNT_ID,
28+
ATTR_CLOUD_AVAILABILITY_ZONE,
29+
ATTR_CLOUD_PLATFORM,
30+
ATTR_CLOUD_PROVIDER,
31+
ATTR_CLOUD_REGION,
32+
ATTR_HOST_ID,
33+
ATTR_HOST_NAME,
34+
ATTR_HOST_TYPE,
35+
} from '../semconv';
3636

3737
import * as http from 'http';
3838

@@ -66,14 +66,14 @@ class AlibabaCloudEcsDetector implements ResourceDetector {
6666
);
6767

6868
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,
69+
ATTR_CLOUD_PROVIDER,
70+
ATTR_CLOUD_PLATFORM,
71+
ATTR_CLOUD_ACCOUNT_ID,
72+
ATTR_CLOUD_REGION,
73+
ATTR_CLOUD_AVAILABILITY_ZONE,
74+
ATTR_HOST_ID,
75+
ATTR_HOST_TYPE,
76+
ATTR_HOST_NAME,
7777
];
7878

7979
const attributes = {} as DetectedResourceAttributes;
@@ -98,14 +98,14 @@ class AlibabaCloudEcsDetector implements ResourceDetector {
9898
const hostname = await this._fetchHost();
9999

100100
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,
101+
[ATTR_CLOUD_PROVIDER]: CLOUD_PROVIDER_VALUE_ALIBABA_CLOUD,
102+
[ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_ALIBABA_CLOUD_ECS,
103+
[ATTR_CLOUD_ACCOUNT_ID]: accountId,
104+
[ATTR_CLOUD_REGION]: region,
105+
[ATTR_CLOUD_AVAILABILITY_ZONE]: availabilityZone,
106+
[ATTR_HOST_ID]: instanceId,
107+
[ATTR_HOST_TYPE]: instanceType,
108+
[ATTR_HOST_NAME]: hostname,
109109
};
110110
} catch (err: any) {
111111
diag.debug(
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* This file contains a copy of unstable semantic convention definitions
19+
* used by this package.
20+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
21+
*/
22+
23+
/**
24+
* The cloud account ID the resource is assigned to.
25+
*
26+
* @example 111111111111
27+
* @example opentelemetry
28+
*
29+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
30+
*/
31+
export const ATTR_CLOUD_ACCOUNT_ID = 'cloud.account.id' as const;
32+
33+
/**
34+
* Cloud regions often have multiple, isolated locations known as zones to increase availability. Availability zone represents the zone where the resource is running.
35+
*
36+
* @example us-east-1c
37+
*
38+
* @note Availability zones are called "zones" on Alibaba Cloud and Google Cloud.
39+
*
40+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
41+
*/
42+
export const ATTR_CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone' as const;
43+
44+
/**
45+
* The cloud platform in use.
46+
*
47+
* @note The prefix of the service **SHOULD** match the one specified in `cloud.provider`.
48+
*
49+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
50+
*/
51+
export const ATTR_CLOUD_PLATFORM = 'cloud.platform' as const;
52+
53+
/**
54+
* Name of the cloud provider.
55+
*
56+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
57+
*/
58+
export const ATTR_CLOUD_PROVIDER = 'cloud.provider' as const;
59+
60+
/**
61+
* The geographical region within a cloud provider. When associated with a resource, this attribute specifies the region where the resource operates. When calling services or APIs deployed on a cloud, this attribute identifies the region where the called destination is deployed.
62+
*
63+
* @example us-central1
64+
* @example us-east-1
65+
*
66+
* @note Refer to your provider's docs to see the available regions, for example [Alibaba Cloud regions](https://www.alibabacloud.com/help/doc-detail/40654.htm), [AWS regions](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/), [Azure regions](https://azure.microsoft.com/global-infrastructure/geographies/), [Google Cloud regions](https://cloud.google.com/about/locations), or [Tencent Cloud regions](https://www.tencentcloud.com/document/product/213/6091).
67+
*
68+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
69+
*/
70+
export const ATTR_CLOUD_REGION = 'cloud.region' as const;
71+
72+
/**
73+
* Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider. For non-containerized systems, this should be the `machine-id`. See the table below for the sources to use to determine the `machine-id` based on operating system.
74+
*
75+
* @example fdbf79e8af94cb7f9e8df36789187052
76+
*
77+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
78+
*/
79+
export const ATTR_HOST_ID = 'host.id' as const;
80+
81+
/**
82+
* Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
83+
*
84+
* @example opentelemetry-test
85+
*
86+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
87+
*/
88+
export const ATTR_HOST_NAME = 'host.name' as const;
89+
90+
/**
91+
* Type of host. For Cloud, this must be the machine type.
92+
*
93+
* @example n1-standard-1
94+
*
95+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
96+
*/
97+
export const ATTR_HOST_TYPE = 'host.type' as const;
98+
99+
/**
100+
* Enum value "alibaba_cloud_ecs" for attribute {@link ATTR_CLOUD_PLATFORM}.
101+
*
102+
* Alibaba Cloud Elastic Compute Service
103+
*
104+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
105+
*/
106+
export const CLOUD_PLATFORM_VALUE_ALIBABA_CLOUD_ECS =
107+
'alibaba_cloud_ecs' as const;
108+
109+
/**
110+
* Enum value "alibaba_cloud" for attribute {@link ATTR_CLOUD_PROVIDER}.
111+
*
112+
* Alibaba Cloud
113+
*
114+
* @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
115+
*/
116+
export const CLOUD_PROVIDER_VALUE_ALIBABA_CLOUD = 'alibaba_cloud' as const;

packages/resource-detector-alibaba-cloud/test/detectors/AlibabaCloudEcsDetector.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { setTimeout as setTimeoutP } from 'timers/promises';
1818
import * as nock from 'nock';
1919
import * as assert from 'assert';
2020
import { detectResources } from '@opentelemetry/resources';
21-
import { CLOUDPROVIDERVALUES_ALIBABA_CLOUD } from '@opentelemetry/semantic-conventions';
21+
import { CLOUD_PROVIDER_VALUE_ALIBABA_CLOUD } from '../../src/semconv';
2222
import {
2323
assertCloudResource,
2424
assertHostResource,
@@ -74,7 +74,7 @@ describe('alibabaCloudEcsDetector', () => {
7474
assert.ok(resource);
7575

7676
assertCloudResource(resource, {
77-
provider: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
77+
provider: CLOUD_PROVIDER_VALUE_ALIBABA_CLOUD,
7878
accountId: 'my-owner-account-id',
7979
region: 'my-region-id',
8080
zone: 'my-zone-id',

0 commit comments

Comments
 (0)