Skip to content

Commit 76bf07e

Browse files
committed
ichore(resource-detector-gcp): use exported strings for attributes
Use exported strings for Semantic Resource Attributes and Cloud Provider Values. Signed-off-by: maryliag <[email protected]>
1 parent 85cbc8d commit 76bf07e

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
* devDependencies
6161
* @opentelemetry/contrib-test-utils bumped from ^0.36.0 to ^0.37.0
6262

63+
### Dependencies
64+
65+
* The following workspace dependencies were updated
66+
* dependencies
67+
* @opentelemetry/semantic-conventions bumped from ^1.0.0 to ^1.22.0
68+
69+
### Enhancement
70+
71+
* refactor: use exported strings for Semantic Resource Attributes and Cloud Provider Values
72+
6373
## [0.29.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-gcp-v0.29.2...resource-detector-gcp-v0.29.3) (2023-11-13)
6474

6575

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"dependencies": {
5757
"@opentelemetry/core": "^1.0.0",
5858
"@opentelemetry/resources": "^1.0.0",
59-
"@opentelemetry/semantic-conventions": "^1.0.0",
59+
"@opentelemetry/semantic-conventions": "^1.22.0",
6060
"gcp-metadata": "^6.0.0"
6161
},
6262
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme"

detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ import {
2424
} from '@opentelemetry/resources';
2525
import { getEnv } from '@opentelemetry/core';
2626
import {
27-
CloudProviderValues,
28-
SemanticResourceAttributes,
27+
CLOUDPROVIDERVALUES_GCP,
28+
SEMRESATTRS_CLOUD_ACCOUNT_ID,
29+
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
30+
SEMRESATTRS_CLOUD_PROVIDER,
31+
SEMRESATTRS_CONTAINER_NAME,
32+
SEMRESATTRS_HOST_ID,
33+
SEMRESATTRS_HOST_NAME,
34+
SEMRESATTRS_K8S_CLUSTER_NAME,
35+
SEMRESATTRS_K8S_NAMESPACE_NAME,
36+
SEMRESATTRS_K8S_POD_NAME,
2937
} from '@opentelemetry/semantic-conventions';
3038

3139
/**
@@ -58,12 +66,12 @@ class GcpDetector implements Detector {
5866
]);
5967

6068
const attributes: ResourceAttributes = {};
61-
attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID] = projectId;
62-
attributes[SemanticResourceAttributes.HOST_ID] = instanceId;
63-
attributes[SemanticResourceAttributes.HOST_NAME] = hostname;
64-
attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE] = zoneId;
65-
attributes[SemanticResourceAttributes.CLOUD_PROVIDER] =
66-
CloudProviderValues.GCP;
69+
attributes[SEMRESATTRS_CLOUD_ACCOUNT_ID] = projectId;
70+
attributes[SEMRESATTRS_HOST_ID] = instanceId;
71+
attributes[SEMRESATTRS_HOST_NAME] = hostname;
72+
attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = zoneId;
73+
attributes[SEMRESATTRS_CLOUD_PROVIDER] =
74+
CLOUDPROVIDERVALUES_GCP;
6775

6876
if (getEnv().KUBERNETES_SERVICE_HOST)
6977
this._addK8sAttributes(attributes, clusterName);
@@ -78,10 +86,10 @@ class GcpDetector implements Detector {
7886
): void {
7987
const env = getEnv();
8088

81-
attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME] = clusterName;
82-
attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME] = env.NAMESPACE;
83-
attributes[SemanticResourceAttributes.K8S_POD_NAME] = env.HOSTNAME;
84-
attributes[SemanticResourceAttributes.CONTAINER_NAME] = env.CONTAINER_NAME;
89+
attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName;
90+
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE;
91+
attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME;
92+
attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
8593
}
8694

8795
/** Gets project id from GCP project metadata. */

package-lock.json

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

0 commit comments

Comments
 (0)