Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resources)!: do not read environment variables from window #5466

Conversation

pichlermarc
Copy link
Member

Which problem is this PR solving?

Migrates from getEnv() to using the new get*FromEnv() methods added in #5443. Also inlines the defaults. This drops "env var configuration" (via window.OTEL_*) in browser environments.

This breaking change will basically make the EnvDetector a no-op detector for browser environments.

Refs #5217

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Adapted unit tests

@pichlermarc pichlermarc force-pushed the feat/migrate-from-getenv-resources branch from 8255f87 to b0cbbe0 Compare February 13, 2025 11:19
@pichlermarc pichlermarc changed the title Feat/migrate from getenv resources feat(resources)!: do not read environment variables from window b0cbbe0 Feb 13, 2025
@pichlermarc pichlermarc force-pushed the feat/migrate-from-getenv-resources branch from 1ff2e02 to b100bd6 Compare February 13, 2025 11:21
@pichlermarc pichlermarc changed the title feat(resources)!: do not read environment variables from window b0cbbe0 feat(resources)!: do not read environment variables from windo Feb 13, 2025
@pichlermarc pichlermarc changed the title feat(resources)!: do not read environment variables from windo feat(resources)!: do not read environment variables from window Feb 13, 2025
@pichlermarc pichlermarc added the target:next-major-release This PR targets the next major release (`next` branch) label Feb 13, 2025
@pichlermarc pichlermarc added this to the OpenTelemetry SDK 2.0 milestone Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.90%. Comparing base (4b8ae0c) to head (b1568eb).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5466      +/-   ##
==========================================
- Coverage   94.90%   94.90%   -0.01%     
==========================================
  Files         308      308              
  Lines        7975     7974       -1     
  Branches     1677     1677              
==========================================
- Hits         7569     7568       -1     
  Misses        406      406              
Files with missing lines Coverage Δ
...entelemetry-resources/src/detectors/EnvDetector.ts 93.87% <100.00%> (-0.13%) ⬇️

@pichlermarc pichlermarc force-pushed the feat/migrate-from-getenv-resources branch from 54e1a1c to b100bd6 Compare February 13, 2025 12:48
@pichlermarc pichlermarc marked this pull request as ready for review February 13, 2025 13:30
@pichlermarc pichlermarc requested a review from a team as a code owner February 13, 2025 13:30
});
});

describe('with invalid env', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

with the new method is no longer possible to have invalid values?
or doesn't matter because it returns the empty and you're already testing that below?

Copy link
Member Author

@pichlermarc pichlermarc Feb 13, 2025

Choose a reason for hiding this comment

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

These are the browser tests that before this PR allowed for users to set window.OTEL_SERVICE_NAME. Now on the browser this will always return an empty resource, as the new functions always return undefined in the browser.

That means that the EnvDetector is now a no-op detector for Browsers, hence no need to test many inputs anymore. 🙂

@pichlermarc pichlermarc added this pull request to the merge queue Feb 13, 2025
Merged via the queue into open-telemetry:main with commit 60f2ce9 Feb 13, 2025
18 checks passed
@pichlermarc pichlermarc deleted the feat/migrate-from-getenv-resources branch February 13, 2025 17:31
trentm pushed a commit to trentm/opentelemetry-js that referenced this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target:next-major-release This PR targets the next major release (`next` branch)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants