Skip to content

Commit 42693f8

Browse files
authored
fix(configuration): do not validate OTEL_CONFIG_FILE value before using it for file config (open-telemetry#6643)
1 parent c5b448e commit 42693f8

5 files changed

Lines changed: 16 additions & 37 deletions

File tree

experimental/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
1010

1111
### :rocket: Features
1212

13+
* feat(configuration): auto-generate TypeScript types from OTel declarative config JSON schema (stable v1.0.0) using `json-schema-to-typescript` and `ajv` [#6533](https://github.com/open-telemetry/opentelemetry-js/pull/6533) @MikeGoldsmith
14+
1315
### :bug: Bug Fixes
1416

17+
* fix(configuration): do not validate `OTEL_CONFIG_FILE` value before using it for file config [#6643](https://github.com/open-telemetry/opentelemetry-js/pull/6643) @trentm
18+
1519
### :books: Documentation
1620

1721
### :house: Internal
@@ -48,7 +52,6 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
4852

4953
### :rocket: Features
5054

51-
* feat(configuration): auto-generate TypeScript types from OTel declarative config JSON schema (stable v1.0.0) using `json-schema-to-typescript` and `ajv` [#6533](https://github.com/open-telemetry/opentelemetry-js/pull/6533)
5255
* feat(otlp-transformer): add custom protobuf logs serializer [#6228](https://github.com/open-telemetry/opentelemetry-js/pull/6228) @pichlermarc
5356
* feat(otlp-transformer): add custom protobuf logs export response deserializer [#6530](https://github.com/open-telemetry/opentelemetry-js/pull/6530) @pichlermarc
5457
* feat(sdk-node): add `buildSamplerFromConfig` to construct a sampler from a declarative config model [#6536](https://github.com/open-telemetry/opentelemetry-js/pull/6536) @ravitheja4531-cell

experimental/packages/configuration/src/ConfigFactory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { getStringFromEnv } from '@opentelemetry/core';
67
import type { ConfigFactory } from './IConfigFactory';
78
import { EnvironmentConfigFactory } from './EnvironmentConfigFactory';
8-
import { FileConfigFactory, hasValidConfigFile } from './FileConfigFactory';
9+
import { FileConfigFactory } from './FileConfigFactory';
910

1011
export function createConfigFactory(): ConfigFactory {
11-
if (hasValidConfigFile()) {
12+
const configFile = getStringFromEnv('OTEL_CONFIG_FILE');
13+
if (configFile) {
1214
return new FileConfigFactory();
1315
}
1416
return new EnvironmentConfigFactory();

experimental/packages/configuration/src/FileConfigFactory.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ export class FileConfigFactory implements ConfigFactory {
3333
}
3434
}
3535

36-
export function hasValidConfigFile(): boolean {
37-
const configFile = getStringFromEnv('OTEL_CONFIG_FILE');
38-
if (configFile) {
39-
if (
40-
!(configFile.endsWith('.yaml') || configFile.endsWith('.yml')) ||
41-
!fs.existsSync(configFile)
42-
) {
43-
diag.warn(
44-
`Config file ${configFile} set on OTEL_CONFIG_FILE is not valid`
45-
);
46-
return false;
47-
}
48-
return true;
49-
}
50-
return false;
51-
}
52-
5336
export function parseConfigFile(): ConfigurationModel {
5437
const supportedFileVersionPattern = /^1\.0$/;
5538
const configFile = getStringFromEnv('OTEL_CONFIG_FILE') || '';

experimental/packages/configuration/test/ConfigFactory.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,14 +2287,14 @@ describe('ConfigFactory', function () {
22872287
});
22882288
});
22892289

2290-
it('should return error from invalid config file', function () {
2291-
const warnSpy = Sinon.spy(diag, 'warn');
2292-
process.env.OTEL_CONFIG_FILE = './fixtures/invalid.txt';
2293-
createConfigFactory();
2294-
Sinon.assert.calledWith(
2295-
warnSpy,
2296-
'Config file ./fixtures/invalid.txt set on OTEL_CONFIG_FILE is not valid'
2297-
);
2290+
it('should throw on non-existant config file', function () {
2291+
process.env.OTEL_CONFIG_FILE = 'test/fixtures/no-such-file.txt';
2292+
try {
2293+
createConfigFactory();
2294+
} catch (err) {
2295+
assert.ok(err);
2296+
assert.equal(err.code, 'ENOENT');
2297+
}
22982298
});
22992299

23002300
it('should throw from invalid config file format', function () {

experimental/packages/opentelemetry-sdk-node/test/start.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ describe('startNodeSDK', function () {
213213
await sdk.shutdown();
214214
});
215215

216-
it('should return NOOP_SDK when disabled is true', async () => {
217-
process.env.OTEL_CONFIG_FILE = 'test/fixtures/kitchen-sink.yaml';
218-
const sdk = startNodeSDK({});
219-
220-
assertDefaultContextManagerRegistered();
221-
222-
await sdk.shutdown();
223-
});
224-
225216
it('should not register a diag logger when OTEL_LOG_LEVEL is not set', async () => {
226217
delete process.env.OTEL_LOG_LEVEL;
227218
const spy = Sinon.spy(diag, 'setLogger');

0 commit comments

Comments
 (0)