From 3419fb073165abcb4fd4021749d2cc0c728c468a Mon Sep 17 00:00:00 2001 From: maryliag Date: Sun, 19 Oct 2025 23:47:10 -0400 Subject: [PATCH 1/7] update exemple --- .../test/fixtures/kitchen-sink.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/experimental/packages/opentelemetry-configuration/test/fixtures/kitchen-sink.yaml b/experimental/packages/opentelemetry-configuration/test/fixtures/kitchen-sink.yaml index 85c40c0526e..f44e11628dd 100644 --- a/experimental/packages/opentelemetry-configuration/test/fixtures/kitchen-sink.yaml +++ b/experimental/packages/opentelemetry-configuration/test/fixtures/kitchen-sink.yaml @@ -8,13 +8,13 @@ # The file format version. # The yaml format is documented at # https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema -file_format: "1.0-rc.1" +file_format: "1.0-rc.2" # Configure if the SDK is disabled or not. # If omitted or null, false is used. disabled: false # Configure the log level of the internal logger used by the SDK. # If omitted, info is used. -log_level: debug +log_level: info # Configure general attribute limits. See also tracer_provider.limits, logger_provider.limits. attribute_limits: # Configure max attribute value size. @@ -200,12 +200,6 @@ meter_provider: # Configure port. # If omitted or null, 9464 is used. port: 9464 - # Configure Prometheus Exporter to produce metrics without a unit suffix or UNIT metadata. - # If omitted or null, false is used. - without_units: false - # Configure Prometheus Exporter to produce metrics without a type suffix. - # If omitted or null, false is used. - without_type_suffix: false # Configure Prometheus Exporter to produce metrics without a scope info metric. # If omitted or null, false is used. without_scope_info: false @@ -225,6 +219,15 @@ meter_provider: # If omitted, .included resource attributes are included. excluded: - "service.attr1" + # Configure how Prometheus metrics are exposed. Values include: + # + # * UnderscoreEscapingWithSuffixes, the default. This fully escapes metric names for classic Prometheus metric name compatibility, and includes appending type and unit suffixes. + # * UnderscoreEscapingWithoutSuffixes, metric names will continue to escape special characters to _, but suffixes won't be attached. + # * NoUTF8EscapingWithSuffixes will disable changing special characters to _. Special suffixes like units and _total for counters will be attached. + # * NoTranslation. This strategy bypasses all metric and label name translation, passing them through unaltered. + # + # If omitted or null, UnderscoreEscapingWithSuffixes is used. + translation_strategy: UnderscoreEscapingWithSuffixes # Configure metric producers. producers: - # Configure metric producer to be opencensus. From 71c777d4667c1b265c879cba4112896742eacb87 Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 23 Oct 2025 23:20:04 -0400 Subject: [PATCH 2/7] add attribute from attribute list env variables --- experimental/CHANGELOG.md | 2 ++ .../src/EnvironmentConfigProvider.ts | 12 +++++++++++- .../opentelemetry-configuration/src/index.ts | 2 +- .../test/ConfigProvider.test.ts | 12 ++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index e81dec8e1d2..ff9dcab0852 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -6,6 +6,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ## Unreleased +* feat(opentelemetry-configuration): set attributes from attribute list from env variables [#6029](https://github.com/open-telemetry/opentelemetry-js/pull/6029) @maryliag + ### :boom: Breaking Changes ### :rocket: Features diff --git a/experimental/packages/opentelemetry-configuration/src/EnvironmentConfigProvider.ts b/experimental/packages/opentelemetry-configuration/src/EnvironmentConfigProvider.ts index c96958a5d1e..c6969cb99a2 100644 --- a/experimental/packages/opentelemetry-configuration/src/EnvironmentConfigProvider.ts +++ b/experimental/packages/opentelemetry-configuration/src/EnvironmentConfigProvider.ts @@ -73,8 +73,18 @@ export function setResources(config: ConfigurationModel): void { } const resourceAttrList = getStringFromEnv('OTEL_RESOURCE_ATTRIBUTES'); - if (resourceAttrList) { + const list = getStringListFromEnv('OTEL_RESOURCE_ATTRIBUTES'); + if (list && list.length > 0) { config.resource.attributes_list = resourceAttrList; + config.resource.attributes = []; + for (let i = 0; i < list.length; i++) { + const element = list[i].split('='); + config.resource.attributes.push({ + name: element[0], + value: element[1], + type: 'string', + }); + } } const serviceName = getStringFromEnv('OTEL_SERVICE_NAME'); diff --git a/experimental/packages/opentelemetry-configuration/src/index.ts b/experimental/packages/opentelemetry-configuration/src/index.ts index c97ac1c4fad..fd2dcbefc6d 100644 --- a/experimental/packages/opentelemetry-configuration/src/index.ts +++ b/experimental/packages/opentelemetry-configuration/src/index.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export { EnvironmentConfigProvider } from './EnvironmentConfigProvider'; export type { ConfigProvider } from './IConfigProvider'; export type { ConfigurationModel as Configuration } from './models/configModel'; +export { createConfigProvider } from './ConfigProvider'; diff --git a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts index a85955b0ac2..0ad0c63f02c 100644 --- a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts +++ b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts @@ -809,6 +809,18 @@ describe('ConfigProvider', function () { resource: { attributes_list: 'service.namespace=my-namespace,service.version=1.0.0', + attributes: [ + { + name: 'service.namespace', + value: 'my-namespace', + type: 'string', + }, + { + name: 'service.version', + value: '1.0.0', + type: 'string', + }, + ], }, }; const configProvider = createConfigProvider(); From ad41ff23eba24e00fd33cd63e1f89a8d70050f49 Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 23 Oct 2025 23:25:01 -0400 Subject: [PATCH 3/7] add file --- .../src/FileConfigProvider.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts b/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts index 1da7cdc4dc5..bcd9902aab7 100644 --- a/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts +++ b/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts @@ -121,6 +121,20 @@ export function parseConfigFile(config: ConfigurationModel) { ); if (attrList) { config.resource.attributes_list = attrList; + const list = getStringListFromConfigFile( + parsedContent['resource']?.['attributes_list'] + ); + if (list && list.length > 0) { + config.resource.attributes = []; + for (let i = 0; i < list.length; i++) { + const element = list[i].split('='); + config.resource.attributes.push({ + name: element[0], + value: element[1], + type: 'string', + }); + } + } } const schemaUrl = getStringFromConfigFile( From 5060fe1a8bb7ec25d04b8fc502f6a2daf78d41b1 Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 23 Oct 2025 23:29:31 -0400 Subject: [PATCH 4/7] add check --- .../opentelemetry-configuration/src/FileConfigProvider.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts b/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts index bcd9902aab7..2ddd8a6c52c 100644 --- a/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts +++ b/experimental/packages/opentelemetry-configuration/src/FileConfigProvider.ts @@ -124,7 +124,11 @@ export function parseConfigFile(config: ConfigurationModel) { const list = getStringListFromConfigFile( parsedContent['resource']?.['attributes_list'] ); - if (list && list.length > 0) { + if ( + list && + list.length > 0 && + parsedContent['resource']?.['attributes'] == null + ) { config.resource.attributes = []; for (let i = 0; i < list.length; i++) { const element = list[i].split('='); From 502a620be2d7e4935efaeaf4cfb455eb52636ca2 Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 23 Oct 2025 23:31:47 -0400 Subject: [PATCH 5/7] update changelog --- experimental/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index ff9dcab0852..93ca1e3c020 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -6,7 +6,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ## Unreleased -* feat(opentelemetry-configuration): set attributes from attribute list from env variables [#6029](https://github.com/open-telemetry/opentelemetry-js/pull/6029) @maryliag +* feat(opentelemetry-configuration): set attributes from attribute list from env variables [#6043](https://github.com/open-telemetry/opentelemetry-js/pull/6043) @maryliag ### :boom: Breaking Changes From 0a4d64f94be04c5f7a84c840759917f955d374b1 Mon Sep 17 00:00:00 2001 From: maryliag Date: Thu, 23 Oct 2025 23:58:41 -0400 Subject: [PATCH 6/7] increase test coverage --- .../test/ConfigProvider.test.ts | 15 ++++++++++++++- .../test/fixtures/short-config.yml | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts index 0ad0c63f02c..f1942281940 100644 --- a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts +++ b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts @@ -1297,9 +1297,22 @@ describe('ConfigProvider', function () { process.env.OTEL_EXPERIMENTAL_CONFIG_FILE = 'test/fixtures/short-config.yml'; const configProvider = createConfigProvider(); + const expectedConfig: Configuration = { + ...defaultConfig, + resource: { + attributes_list: 'service.instance.id=123', + attributes: [ + { + name: 'service.instance.id', + value: '123', + type: 'string', + }, + ], + }, + }; assert.deepStrictEqual( configProvider.getInstrumentationConfig(), - defaultConfig + expectedConfig ); }); diff --git a/experimental/packages/opentelemetry-configuration/test/fixtures/short-config.yml b/experimental/packages/opentelemetry-configuration/test/fixtures/short-config.yml index 984c87c34a8..0473fbd1b1e 100644 --- a/experimental/packages/opentelemetry-configuration/test/fixtures/short-config.yml +++ b/experimental/packages/opentelemetry-configuration/test/fixtures/short-config.yml @@ -1,2 +1,4 @@ file_format: "1.0-rc.1" -disabled: false \ No newline at end of file +disabled: false +resource: + attributes_list: service.instance.id=123 \ No newline at end of file From dc0b694534b90aea6914c5f56e8aa20a6d26d3cc Mon Sep 17 00:00:00 2001 From: maryliag Date: Fri, 24 Oct 2025 00:08:42 -0400 Subject: [PATCH 7/7] fix lint --- .../opentelemetry-configuration/test/ConfigProvider.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts index f1942281940..4e47ec887a0 100644 --- a/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts +++ b/experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts @@ -1297,7 +1297,7 @@ describe('ConfigProvider', function () { process.env.OTEL_EXPERIMENTAL_CONFIG_FILE = 'test/fixtures/short-config.yml'; const configProvider = createConfigProvider(); - const expectedConfig: Configuration = { + const expectedConfig: Configuration = { ...defaultConfig, resource: { attributes_list: 'service.instance.id=123',