Skip to content

Conversation

@pichlermarc
Copy link
Member

Which problem is this PR solving?

We're planning to remove getEnv() as it does not scale well when everyone has to update @opentelemetry/core to get their env vars. For OTEL_* there will be a replacement utility function. For all others, when the package does not need to be browser-compatible (which seems to be the case here) using process.env directly should be fine.

Refs open-telemetry/opentelemetry-js#5443

Short description of the changes

This PR removes getEnv() with process.env and inlines the defaults from @opentelemetry/core's DEFAULT_ENVIRONMENT

attributes[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_GCP;

if (getEnv().KUBERNETES_SERVICE_HOST)
if (process.env.KUBERNETES_SERVICE_HOST)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: this previously was an empty string when it was unset - now it's undefined. The semantics should be the same other than that.

attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = process.env.NAMESPACE ?? '';
attributes[SEMRESATTRS_K8S_POD_NAME] = process.env.HOSTNAME ?? '';
attributes[SEMRESATTRS_CONTAINER_NAME] = process.env.CONTAINER_NAME ?? '';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pichlermarc pichlermarc force-pushed the chore/gcp-stop-using-getenv branch from 3153771 to 8602d5b Compare February 11, 2025 14:26
@codecov
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.40%. Comparing base (db8245a) to head (be6f4e7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2705      +/-   ##
==========================================
- Coverage   92.40%   92.40%   -0.01%     
==========================================
  Files         171      171              
  Lines        8142     8140       -2     
  Branches     1649     1652       +3     
==========================================
- Hits         7524     7522       -2     
  Misses        618      618              
Files with missing lines Coverage Δ
...resource-detector-gcp/src/detectors/GcpDetector.ts 96.22% <100.00%> (-0.14%) ⬇️

@pichlermarc pichlermarc enabled auto-merge (squash) February 12, 2025 09:06
@pichlermarc pichlermarc merged commit 143a1f4 into open-telemetry:main Feb 12, 2025
9 checks passed
@pichlermarc pichlermarc deleted the chore/gcp-stop-using-getenv branch February 12, 2025 09:06
deejay1 pushed a commit to deejay1/opentelemetry-js-contrib that referenced this pull request Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants