Skip to content

Commit 143a1f4

Browse files
authored
refactor(resource-detector-gcp): migrate away from getEnv() (open-telemetry#2705)
1 parent db8245a commit 143a1f4

File tree

1 file changed

+4
-7
lines changed
  • detectors/node/opentelemetry-resource-detector-gcp/src/detectors

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
ResourceAttributes,
2525
IResource,
2626
} from '@opentelemetry/resources';
27-
import { getEnv } from '@opentelemetry/core';
2827
import {
2928
CLOUDPROVIDERVALUES_GCP,
3029
SEMRESATTRS_CLOUD_ACCOUNT_ID,
@@ -79,7 +78,7 @@ class GcpDetector implements DetectorSync {
7978
attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = zoneId;
8079
attributes[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_GCP;
8180

82-
if (getEnv().KUBERNETES_SERVICE_HOST)
81+
if (process.env.KUBERNETES_SERVICE_HOST)
8382
this._addK8sAttributes(attributes, clusterName);
8483

8584
return attributes;
@@ -90,12 +89,10 @@ class GcpDetector implements DetectorSync {
9089
attributes: ResourceAttributes,
9190
clusterName: string
9291
): void {
93-
const env = getEnv();
94-
9592
attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName;
96-
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE;
97-
attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME;
98-
attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
93+
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = process.env.NAMESPACE ?? '';
94+
attributes[SEMRESATTRS_K8S_POD_NAME] = process.env.HOSTNAME ?? '';
95+
attributes[SEMRESATTRS_CONTAINER_NAME] = process.env.CONTAINER_NAME ?? '';
9996
}
10097

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

0 commit comments

Comments
 (0)