refactor(otlp-exporter-base): use `getStringFromEnv` instead of `process.env` (#5594)

Signed-off-by: Weyert de Boer <wdb@innerfuse.biz>
Co-authored-by: David Luna <david.luna@elastic.co>
Co-authored-by: Trent Mick <trentm@gmail.com>
This commit is contained in:
Weyert de Boer 2025-08-22 22:24:28 +01:00 committed by GitHub
parent 31640eb500
commit 806e56b388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View File

@ -27,6 +27,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
### :house: Internal
* refactor(otlp-exporter-base): use getStringFromEnv instead of process.env [#5594](https://github.com/open-telemetry/opentelemetry-js/pull/5594) @weyert
* chore(sdk-logs): refactored imports [#5801](https://github.com/open-telemetry/opentelemetry-js/pull/5801) @svetlanabrennan
## 0.203.0

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { parseKeyPairsIntoRecord } from '@opentelemetry/core';
import { getStringFromEnv, parseKeyPairsIntoRecord } from '@opentelemetry/core';
import { diag } from '@opentelemetry/api';
import { getSharedConfigurationFromEnvironment } from './shared-env-configuration';
import { OtlpHttpConfiguration } from './otlp-http-configuration';
@ -22,10 +22,12 @@ import { wrapStaticHeadersInFunction } from './shared-configuration';
function getStaticHeadersFromEnv(
signalIdentifier: string
): Record<string, string> | undefined {
const signalSpecificRawHeaders =
process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`]?.trim();
const nonSignalSpecificRawHeaders =
process.env['OTEL_EXPORTER_OTLP_HEADERS']?.trim();
const signalSpecificRawHeaders = getStringFromEnv(
`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`
);
const nonSignalSpecificRawHeaders = getStringFromEnv(
'OTEL_EXPORTER_OTLP_HEADERS'
);
const signalSpecificHeaders = parseKeyPairsIntoRecord(
signalSpecificRawHeaders
@ -98,17 +100,18 @@ function appendResourcePathToUrl(
function getNonSpecificUrlFromEnv(
signalResourcePath: string
): string | undefined {
const envUrl = process.env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim();
if (envUrl == null || envUrl === '') {
const envUrl = getStringFromEnv('OTEL_EXPORTER_OTLP_ENDPOINT');
if (envUrl === undefined) {
return undefined;
}
return appendResourcePathToUrl(envUrl, signalResourcePath);
}
function getSpecificUrlFromEnv(signalIdentifier: string): string | undefined {
const envUrl =
process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`]?.trim();
if (envUrl == null || envUrl === '') {
const envUrl = getStringFromEnv(
`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`
);
if (envUrl === undefined) {
return undefined;
}
return appendRootPathToUrlIfNeeded(envUrl);