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

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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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(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.

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