Skip to content

Commit

Permalink
chore(resource-detector-gcp): use exported strings for attributes (#2050
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 <marylia.gutierrez@grafana.com>
  • Loading branch information
maryliag committed Apr 9, 2024
1 parent 1a7b87a commit 6bd62a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
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,11 @@ 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 +85,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 6bd62a2

Please sign in to comment.