-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore OTEL_LOG_LEVEL after starting NodeSDK (#24)
In case there is user code that uses the envvar. It is removed from the env temporarily when creating the NodeSDK so it doesn't use the value and override the 'diag' set by ElasticNodeSDK
- Loading branch information
Showing
6 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Test that usage of `OTEL_LOG_LEVEL` works as expected. | ||
|
||
const {test} = require('tape'); | ||
const {runTestFixtures} = require('./testutils'); | ||
|
||
const testFixtures = [ | ||
{ | ||
name: 'diag default', | ||
args: ['./fixtures/use-diag.js'], | ||
cwd: __dirname, | ||
env: { | ||
NODE_OPTIONS: '--require=../start.js', | ||
}, | ||
// verbose: true, | ||
checkResult: (t, err, stdout, stderr) => { | ||
t.error(err); | ||
t.ok(/hi at info/.test(stdout), 'info'); | ||
t.ok(/hi at warn/.test(stdout), 'warn'); | ||
t.ok(/hi at error/.test(stdout), 'error'); | ||
t.ok(/OTEL_LOG_LEVEL: undefined/.test(stdout), 'envvar'); | ||
}, | ||
}, | ||
{ | ||
name: 'diag OTEL_LOG_LEVEL=debug', | ||
args: ['./fixtures/use-diag.js'], | ||
cwd: __dirname, | ||
env: { | ||
NODE_OPTIONS: '--require=../start.js', | ||
OTEL_LOG_LEVEL: 'debug', | ||
}, | ||
// verbose: true, | ||
checkResult: (t, err, stdout, stderr) => { | ||
t.error(err); | ||
t.ok(/hi at debug/.test(stdout), 'debug'); | ||
t.ok(/hi at info/.test(stdout), 'info'); | ||
t.ok(/hi at warn/.test(stdout), 'warn'); | ||
t.ok(/hi at error/.test(stdout), 'error'); | ||
t.ok(/OTEL_LOG_LEVEL: debug/.test(stdout), 'envvar'); | ||
}, | ||
}, | ||
{ | ||
name: 'diag OTEL_LOG_LEVEL=VerBoSe (allow any case)', | ||
args: ['./fixtures/use-diag.js'], | ||
cwd: __dirname, | ||
env: { | ||
NODE_OPTIONS: '--require=../start.js', | ||
OTEL_LOG_LEVEL: 'VerBoSe', | ||
}, | ||
// verbose: true, | ||
checkResult: (t, err, stdout, stderr) => { | ||
t.error(err); | ||
t.ok(/hi at verbose/.test(stdout), 'verbose'); | ||
t.ok(/hi at debug/.test(stdout), 'debug'); | ||
t.ok(/hi at info/.test(stdout), 'info'); | ||
t.ok(/hi at warn/.test(stdout), 'warn'); | ||
t.ok(/hi at error/.test(stdout), 'error'); | ||
t.ok(/OTEL_LOG_LEVEL: VerBoSe/.test(stdout), 'envvar'); | ||
}, | ||
}, | ||
]; | ||
|
||
test('OTEL_LOG_LEVEL', (suite) => { | ||
runTestFixtures(suite, testFixtures); | ||
suite.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const {diag} = require('@opentelemetry/api'); | ||
|
||
diag.verbose('hi at verbose'); | ||
diag.debug('hi at debug'); | ||
diag.info('hi at info'); | ||
diag.warn('hi at warn'); | ||
diag.error('hi at error'); | ||
|
||
console.log('OTEL_LOG_LEVEL:', process.env.OTEL_LOG_LEVEL); |