Skip to content

Commit

Permalink
fix(core): align inconsistent behavior of getEnv() and getEnvWithoutD…
Browse files Browse the repository at this point in the history
…efaults() when a process polyfill is used (#4649)

* fix(core): align inconsistent behavior of getEnv() and getEnvWithoutDefaults() when a process polyfill is used

* Update CHANGELOG.md
  • Loading branch information
pichlermarc committed May 6, 2024
1 parent 307e33a commit fe132d7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :bug: (Bug Fix)

* fix(core): align inconsistent behavior of `getEnv()` and `getEnvWithoutDefaults()` when a `process` polyfill is used [#4648](https://github.com/open-telemetry/opentelemetry-js/pull/4648) @pichlermarc
* `getEnvWithoutDefaults()` would use `process.env` if it was defined when running in a browser, while `getEnv()` would always use `_globalThis`. Now both use `_globalThis` when running in a browser.
* fix(resources): prevent circular import (resource -> detector -> resource -> ...) [#4653](https://github.com/open-telemetry/opentelemetry-js/pull/4653) @pichlermarc
* fixes a circular import warning which would appear in rollup when bundling `@opentelemetry/resources`

### :books: (Refine Doc)

### :house: (Internal)
Expand All @@ -29,8 +34,6 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

* fix(sdk-trace-web): fix invalid timings in span events [#4486](https://github.com/open-telemetry/opentelemetry-js/pull/4486) @Abinet18
* fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser [#4561](https://github.com/open-telemetry/opentelemetry-js/issues/4561) @trentm
* fix(resources): prevent circular import (resource -> detector -> resource -> ...) [#4653](https://github.com/open-telemetry/opentelemetry-js/pull/4653) @pichlermarc
* fixes a circular import warning which would appear in rollup when bundling `@opentelemetry/resources`

## 1.23.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export function getEnv(): Required<ENVIRONMENT> {
);
return Object.assign({}, DEFAULT_ENVIRONMENT, globalEnv);
}

export function getEnvWithoutDefaults(): ENVIRONMENT {
return parseEnvironment(_globalThis as typeof globalThis & RAW_ENVIRONMENT);
}
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/platform/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export * from './environment';
export { getEnvWithoutDefaults, getEnv } from './environment';
export * from './globalThis';
export * from './hex-to-base64';
export * from './RandomIdGenerator';
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-core/src/platform/node/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ export function getEnv(): Required<ENVIRONMENT> {
const processEnv = parseEnvironment(process.env as RAW_ENVIRONMENT);
return Object.assign({}, DEFAULT_ENVIRONMENT, processEnv);
}

export function getEnvWithoutDefaults(): ENVIRONMENT {
return parseEnvironment(process.env as RAW_ENVIRONMENT);
}
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/platform/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export * from './environment';
export { getEnvWithoutDefaults, getEnv } from './environment';
export * from './globalThis';
export * from './hex-to-base64';
export * from './RandomIdGenerator';
Expand Down
11 changes: 0 additions & 11 deletions packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { DiagLogLevel } from '@opentelemetry/api';
import { TracesSamplerValues } from './sampling';
import { _globalThis } from '../platform/browser/globalThis';

const DEFAULT_LIST_SEPARATOR = ',';

Expand Down Expand Up @@ -369,13 +368,3 @@ export function parseEnvironment(values: RAW_ENVIRONMENT): ENVIRONMENT {

return environment;
}

/**
* Get environment in node or browser without
* populating default values.
*/
export function getEnvWithoutDefaults(): ENVIRONMENT {
return typeof process !== 'undefined' && process && process.env
? parseEnvironment(process.env as RAW_ENVIRONMENT)
: parseEnvironment(_globalThis as typeof globalThis & RAW_ENVIRONMENT);
}

0 comments on commit fe132d7

Please sign in to comment.