From 24e4a7345fafd2ec1cc1c6001432d9eb80ba7920 Mon Sep 17 00:00:00 2001 From: danstarns Date: Sat, 15 Jun 2024 22:07:31 +0100 Subject: [PATCH 1/3] refactor: reduce and simplify usage of getEnv() --- .../src/platform/config.ts | 27 ++++++++------ .../src/platform/browser/OTLPLogExporter.ts | 32 ++++++++++------- .../src/platform/node/OTLPLogExporter.ts | 30 ++++++++++------ .../src/platform/browser/OTLPTraceExporter.ts | 32 +++++++++++------ .../src/platform/node/OTLPTraceExporter.ts | 32 +++++++++++------ .../src/platform/browser/OTLPTraceExporter.ts | 32 +++++++++++------ .../src/platform/node/OTLPTraceExporter.ts | 32 +++++++++++------ .../platform/browser/OTLPMetricExporter.ts | 34 +++++++++++------- .../src/platform/node/OTLPMetricExporter.ts | 34 +++++++++++------- .../src/OTLPMetricExporter.ts | 36 +++++++++++-------- .../src/config.ts | 20 +++++------ 11 files changed, 213 insertions(+), 128 deletions(-) diff --git a/experimental/packages/exporter-logs-otlp-http/src/platform/config.ts b/experimental/packages/exporter-logs-otlp-http/src/platform/config.ts index a41ee96468..5ce6eb75f7 100644 --- a/experimental/packages/exporter-logs-otlp-http/src/platform/config.ts +++ b/experimental/packages/exporter-logs-otlp-http/src/platform/config.ts @@ -30,14 +30,21 @@ export const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_ * @returns url string */ export function getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded(env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts index a1ed000d66..259ce6a080 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/browser/OTLPLogExporter.ts @@ -40,24 +40,30 @@ export class OTLPLogExporter { constructor(config: OTLPExporterConfigBase = {}) { super(config, ProtobufLogsSerializer, 'application/x-protobuf'); + const env = getEnv(); this._headers = Object.assign( this._headers, - baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS - ) + baggageUtils.parseKeyPairsIntoRecord(env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) ); } getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded(env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts index 989d5e237a..de3f8697b1 100644 --- a/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts +++ b/experimental/packages/exporter-logs-otlp-proto/src/platform/node/OTLPLogExporter.ts @@ -46,26 +46,34 @@ export class OTLPLogExporter { constructor(config: OTLPExporterConfigBase = {}) { super(config, ProtobufLogsSerializer, 'application/x-protobuf'); + const env = getEnv(); this.headers = { ...this.headers, ...USER_AGENT, ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_LOGS_HEADERS + env.OTEL_EXPORTER_OTLP_LOGS_HEADERS ), ...parseHeaders(config?.headers), }; } getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded(env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index 594054cf49..b19ce672fd 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -39,24 +39,34 @@ export class OTLPTraceExporter { constructor(config: OTLPExporterConfigBase = {}) { super(config, JsonTraceSerializer, 'application/json'); + const env = getEnv(); this._headers = Object.assign( this._headers, baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS + env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ) ); } getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index e8e77831fb..6a978bc897 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -44,26 +44,36 @@ export class OTLPTraceExporter { constructor(config: OTLPExporterNodeConfigBase = {}) { super(config, JsonTraceSerializer, 'application/json'); + const env = getEnv(); this.headers = { ...this.headers, ...USER_AGENT, ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS + env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ), ...parseHeaders(config?.headers), }; } getDefaultUrl(config: OTLPExporterNodeConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts index 0de8a9a962..f474e95788 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/platform/browser/OTLPTraceExporter.ts @@ -39,24 +39,34 @@ export class OTLPTraceExporter { constructor(config: OTLPExporterConfigBase = {}) { super(config, ProtobufTraceSerializer, 'application/x-protobuf'); + const env = getEnv(); this._headers = Object.assign( this._headers, baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS + env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ) ); } getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts index bb3c916dbb..75637863ed 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/platform/node/OTLPTraceExporter.ts @@ -44,26 +44,36 @@ export class OTLPTraceExporter { constructor(config: OTLPExporterNodeConfigBase = {}) { super(config, ProtobufTraceSerializer, 'application/x-protobuf'); + const env = getEnv(); this.headers = { ...this.headers, ...USER_AGENT, ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS + env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ), ...parseHeaders(config?.headers), }; } getDefaultUrl(config: OTLPExporterNodeConfigBase) { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 890f1e9deb..0fa43efa78 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -38,27 +38,35 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase< > { constructor(config?: OTLPMetricExporterOptions & OTLPExporterConfigBase) { super(config, JsonMetricsSerializer, 'application/json'); + const env = getEnv(); this._headers = Object.assign( this._headers, baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS + env.OTEL_EXPORTER_OTLP_METRICS_HEADERS ) ); } getDefaultUrl(config: OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded( - getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index d812c37b26..1f0dc59b27 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -43,29 +43,37 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config, JsonMetricsSerializer, 'application/json'); + const env = getEnv(); this.headers = { ...this.headers, ...USER_AGENT, ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS + env.OTEL_EXPORTER_OTLP_METRICS_HEADERS ), ...parseHeaders(config?.headers), }; } getDefaultUrl(config: OTLPExporterNodeConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded( - getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index 150181db01..944b3e892b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -43,29 +43,37 @@ class OTLPMetricExporterNodeProxy extends OTLPExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config, ProtobufMetricsSerializer, 'application/x-protobuf'); + const env = getEnv(); this.headers = { ...this.headers, ...USER_AGENT, ...baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS + env.OTEL_EXPORTER_OTLP_METRICS_HEADERS ), ...parseHeaders(config?.headers), }; } - getDefaultUrl(config: OTLPExporterNodeConfigBase) { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? appendRootPathToUrlIfNeeded( - getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrl( - getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, - DEFAULT_COLLECTOR_RESOURCE_PATH - ) - : DEFAULT_COLLECTOR_URL; + getDefaultUrl(config: OTLPExporterNodeConfigBase): string { + if (typeof config.url === 'string') { + return config.url; + } + + const env = getEnv(); + if (env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0) { + return appendRootPathToUrlIfNeeded( + env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + ); + } + + if (env.OTEL_EXPORTER_OTLP_ENDPOINT.length > 0) { + return appendResourcePathToUrl( + env.OTEL_EXPORTER_OTLP_ENDPOINT, + DEFAULT_COLLECTOR_RESOURCE_PATH + ); + } + + return DEFAULT_COLLECTOR_URL; } } diff --git a/packages/opentelemetry-sdk-trace-base/src/config.ts b/packages/opentelemetry-sdk-trace-base/src/config.ts index 3448b793da..f97a383599 100644 --- a/packages/opentelemetry-sdk-trace-base/src/config.ts +++ b/packages/opentelemetry-sdk-trace-base/src/config.ts @@ -36,23 +36,23 @@ const DEFAULT_RATIO = 1; // object needs to be wrapped in this function and called when needed otherwise // envs are parsed before tests are ran - causes tests using these envs to fail export function loadDefaultConfig() { + const _env = getEnv(); + return { sampler: buildSamplerFromEnv(env), forceFlushTimeoutMillis: 30000, generalLimits: { - attributeValueLengthLimit: getEnv().OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, - attributeCountLimit: getEnv().OTEL_ATTRIBUTE_COUNT_LIMIT, + attributeValueLengthLimit: _env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, + attributeCountLimit: _env.OTEL_ATTRIBUTE_COUNT_LIMIT, }, spanLimits: { - attributeValueLengthLimit: - getEnv().OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, - attributeCountLimit: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, - linkCountLimit: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT, - eventCountLimit: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT, + attributeValueLengthLimit: _env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, + attributeCountLimit: _env.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, + linkCountLimit: _env.OTEL_SPAN_LINK_COUNT_LIMIT, + eventCountLimit: _env.OTEL_SPAN_EVENT_COUNT_LIMIT, attributePerEventCountLimit: - getEnv().OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, - attributePerLinkCountLimit: - getEnv().OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT, + _env.OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, + attributePerLinkCountLimit: _env.OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT, }, }; } From 18da70a4b75144742f6e307ee44e47fc38edebe6 Mon Sep 17 00:00:00 2001 From: danstarns Date: Mon, 24 Jun 2024 14:55:25 +0100 Subject: [PATCH 2/3] docs: update CHANGELOG --- CHANGELOG.md | 1 + experimental/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2445bb96ab..67cb65a1af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * refactor(context-zone-peer-dep): use explicit exports [#4785](https://github.com/open-telemetry/opentelemetry-js/pull/4787) @pichlermarc * refactor(context-async-hooks): use explicit exports [#4785](https://github.com/open-telemetry/opentelemetry-js/pull/4786) @pichlermarc +* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns ## 1.25.0 diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index c46df852a2..f5e878a771 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to experimental packages in this project will be documented ### :house: (Internal) * test: add `npm run maint:regenerate-test-certs` maintenance script and regenerate recently expired test certs [#4777](https://github.com/open-telemetry/opentelemetry-js/pull/4777) +* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns ## 0.52.0 From 3b948b5bb2f69603214e573a91c4f0ad05ee40ec Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 25 Jun 2024 09:42:48 +0200 Subject: [PATCH 3/3] fixup! docs: update CHANGELOG --- CHANGELOG.md | 3 ++- experimental/CHANGELOG.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eacf2247df..644972b950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :house: (Internal) +* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns + ## 1.25.1 ### :books: (Refine Doc) @@ -28,7 +30,6 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * refactor(context-zone-peer-dep): use explicit exports [#4785](https://github.com/open-telemetry/opentelemetry-js/pull/4787) @pichlermarc * refactor(context-async-hooks): use explicit exports [#4785](https://github.com/open-telemetry/opentelemetry-js/pull/4786) @pichlermarc -* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns ## 1.25.0 diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 242432fffc..a0b2c19201 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -15,6 +15,8 @@ All notable changes to experimental packages in this project will be documented ### :house: (Internal) +* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns + ## 0.52.1 ### :rocket: (Enhancement) @@ -31,7 +33,6 @@ All notable changes to experimental packages in this project will be documented ### :house: (Internal) * test: add `npm run maint:regenerate-test-certs` maintenance script and regenerate recently expired test certs [#4777](https://github.com/open-telemetry/opentelemetry-js/pull/4777) -* refactor: Simplify the code for the `getEnv` function [#4799](https://github.com/open-telemetry/opentelemetry-js/pull/4799) @danstarns ## 0.52.0