From f364139c68173783f12e8acf86dc7ab0600e44b4 Mon Sep 17 00:00:00 2001 From: maryliag Date: Wed, 27 Mar 2024 11:22:03 -0400 Subject: [PATCH] chore(resource-detector-gcp): use exported strings for attributes Use exported strings for Semantic Resource Attributes and Cloud Provider Values. Signed-off-by: maryliag --- .../CHANGELOG.md | 10 ++++++ .../package.json | 2 +- .../src/detectors/GcpDetector.ts | 32 ++++++++++++------- package-lock.json | 4 +-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md b/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md index 8febd065ce..926301aa50 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md +++ b/detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md @@ -60,6 +60,16 @@ * devDependencies * @opentelemetry/contrib-test-utils bumped from ^0.36.0 to ^0.37.0 +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @opentelemetry/semantic-conventions bumped from ^1.0.0 to ^1.22.0 + +### Enhancement + +* refactor: use exported strings for Semantic Resource Attributes and Cloud Provider Values + ## [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) diff --git a/detectors/node/opentelemetry-resource-detector-gcp/package.json b/detectors/node/opentelemetry-resource-detector-gcp/package.json index 1a928aec8d..5f19d278ec 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/package.json +++ b/detectors/node/opentelemetry-resource-detector-gcp/package.json @@ -56,7 +56,7 @@ "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "gcp-metadata": "^6.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme" diff --git a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts index 206bb4d1d3..f66c6a0cab 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-gcp/src/detectors/GcpDetector.ts @@ -24,8 +24,16 @@ import { } from '@opentelemetry/resources'; import { getEnv } from '@opentelemetry/core'; import { - CloudProviderValues, - SemanticResourceAttributes, + CLOUDPROVIDERVALUES_GCP, + SEMRESATTRS_CLOUD_ACCOUNT_ID, + SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, + SEMRESATTRS_CLOUD_PROVIDER, + SEMRESATTRS_CONTAINER_NAME, + SEMRESATTRS_HOST_ID, + SEMRESATTRS_HOST_NAME, + SEMRESATTRS_K8S_CLUSTER_NAME, + SEMRESATTRS_K8S_NAMESPACE_NAME, + SEMRESATTRS_K8S_POD_NAME, } from '@opentelemetry/semantic-conventions'; /** @@ -58,12 +66,12 @@ class GcpDetector implements Detector { ]); const attributes: ResourceAttributes = {}; - attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID] = projectId; - attributes[SemanticResourceAttributes.HOST_ID] = instanceId; - attributes[SemanticResourceAttributes.HOST_NAME] = hostname; - attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE] = zoneId; - attributes[SemanticResourceAttributes.CLOUD_PROVIDER] = - CloudProviderValues.GCP; + attributes[SEMRESATTRS_CLOUD_ACCOUNT_ID] = projectId; + attributes[SEMRESATTRS_HOST_ID] = instanceId; + attributes[SEMRESATTRS_HOST_NAME] = hostname; + attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = zoneId; + attributes[SEMRESATTRS_CLOUD_PROVIDER] = + CLOUDPROVIDERVALUES_GCP; if (getEnv().KUBERNETES_SERVICE_HOST) this._addK8sAttributes(attributes, clusterName); @@ -78,10 +86,10 @@ class GcpDetector implements Detector { ): void { const env = getEnv(); - attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME] = clusterName; - attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME] = env.NAMESPACE; - attributes[SemanticResourceAttributes.K8S_POD_NAME] = env.HOSTNAME; - attributes[SemanticResourceAttributes.CONTAINER_NAME] = env.CONTAINER_NAME; + attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName; + attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE; + attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME; + attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME; } /** Gets project id from GCP project metadata. */ diff --git a/package-lock.json b/package-lock.json index 65bcc6f9f4..a4dd3198d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -183,7 +183,7 @@ "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/resources": "^1.0.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "gcp-metadata": "^6.0.0" }, "devDependencies": { @@ -47926,7 +47926,7 @@ "@opentelemetry/contrib-test-utils": "^0.37.0", "@opentelemetry/core": "^1.0.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/semver": "7.5.3",