Skip to content

Commit bdc1dc7

Browse files
committed
chore(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 bdc1dc7

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

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: 19 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,11 @@ 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] = CLOUDPROVIDERVALUES_GCP;
6774

6875
if (getEnv().KUBERNETES_SERVICE_HOST)
6976
this._addK8sAttributes(attributes, clusterName);
@@ -78,10 +85,10 @@ class GcpDetector implements Detector {
7885
): void {
7986
const env = getEnv();
8087

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;
88+
attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName;
89+
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE;
90+
attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME;
91+
attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
8592
}
8693

8794
/** 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)