-
Notifications
You must be signed in to change notification settings - Fork 913
Description
Description
Important
Only actionable for next
branch. Any PRs opened for this MUST be based on and targeted at the next
branch.
The @opentelemetry/core
package contains a browser implementation of getEnv()
that attempts to get the configuration from the _globalThis
(similar to getting env vars from process.env
in Node.js). This behvaior
- duplicates ways to configure components that have to be set up via code anyway
- increases bundle size
- significantly increases test-complexity
- significantly increases code-complexity
- confuses users who are looking for the "right" way to do things
Since removing getEnv()
completely would be quite an undertaking and would result in a large, difficult to review PR, this issue focuses on:
- disabling the functionality of
getEnv()
andgetEnvWithoutDefaults()
so that it does not extract config from_globalThis
- removing any browser tests (run via the
npm run test:browser
script) that tested this behavior.
Since the behavior is then not present anymore when we release 2.0, removing getEnv()
usage for browser code can be a non-breaking change and can be done in a feature-release. We can remove usages of getEnv()
and getEnvWithoutDefaults()
step-by-step throughout the code base as a clean-up in feature releases. This should yield bundle-size improvements and an eventual further reduction of code-complexity.
This issue is considered done when:
-
getEnv()
has been changed returns a copy ofDEFAULT_ENVIRONMENT
for the browser implementation -
getEnvWithoutDefaults()
has been changed to return a new empty object for the browser implementation - any tests that rely on this behavior have been removed or adapted
- note: please do not blindly remove all tests. some tests may be used both in Node.js and Browser (usually in
common
directories) - you may have to adapt some tests and move them to different directories so that the only run on Node.js
- note: please do not blindly remove all tests. some tests may be used both in Node.js and Browser (usually in
- a follow-up issue to track removing
getEnv()
andgetEnvWithoutDefaults()
in a feature release has been created
Code location
opentelemetry-js/packages/opentelemetry-core/src/platform/browser/environment.ts
Lines 28 to 37 in 141b457
export function getEnv(): Required<ENVIRONMENT> { const globalEnv = parseEnvironment( _globalThis as typeof globalThis & RAW_ENVIRONMENT ); return Object.assign({}, DEFAULT_ENVIRONMENT, globalEnv); } export function getEnvWithoutDefaults(): ENVIRONMENT { return parseEnvironment(_globalThis as typeof globalThis & RAW_ENVIRONMENT); }