Skip to content
Merged
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [#6043](https://github.com/open-telemetry/opentelemetry-js/pull/6043) @maryliag

### :boom: Breaking Changes

* feat(otlp-exporter-base)!: allow passing an async function to headers option [#5994](https://github.com/open-telemetry/opentelemetry-js/pull/5994/files) @pichlermarc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ export function parseConfigFile(config: ConfigurationModel) {
);
if (attrList) {
config.resource.attributes_list = attrList;
const list = getStringListFromConfigFile(
parsedContent['resource']?.['attributes_list']
);
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('=');
config.resource.attributes.push({
name: element[0],
value: element[1],
type: 'string',
});
}
}
}

const schemaUrl = getStringFromConfigFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1371,9 +1383,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
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
file_format: "1.0-rc.1"
disabled: false
disabled: false
resource:
attributes_list: service.instance.id=123