Skip to content

[core] make browser-implementation of getEnv() return only defaults, getEnvWithoutDefaults() an empty object  #5217

@pichlermarc

Description

@pichlermarc

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() and getEnvWithoutDefaults() 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 of DEFAULT_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
  • a follow-up issue to track removing getEnv() and getEnvWithoutDefaults() in a feature release has been created

Code location

  • 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);
    }

Metadata

Metadata

Assignees

Labels

needs:refinementThis issue needs to be refined/broken apart into sub-issues before implementationpkg:coretarget:next-major-releaseThis PR targets the next major release (`next` branch)type:featureA feature with no sub-issues to address

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions