Skip to content

Commit

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

Signed-off-by: maryliag <[email protected]>
  • Loading branch information
maryliag committed Mar 27, 2024
1 parent 85cbc8d commit 76bf07e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
10 changes: 10 additions & 0 deletions detectors/node/opentelemetry-resource-detector-gcp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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. */
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 76bf07e

Please sign in to comment.