Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg committed Feb 26, 2024
1 parent 027e30c commit fdce25c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Log injection can be disabled with the `disableLogCorrelation: true` option.
| Option | Type | Description |
| ----------------------- | ----------------- | ----------- |
| `disableLogSending` | `boolean` | Whether to disable [log sending](#log-sending). Default `false`. |
| `logSeverity` | `SeverityNumber` | Control severity level for [log sending](#log-sending). Default `SeverityNumber.UNSPECIFIED`. |
| `logSeverity` | `SeverityNumber` | Control severity level for [log sending](#log-sending). Default `SeverityNumber.UNSPECIFIED`, it will use Bunnyan Logger's current level when unspecified. |
| `disableLogCorrelation` | `boolean` | Whether to disable [log correlation](#log-correlation). Default `false`. |
| `logHook` | `LogHookFunction` | An option hook to inject additional context to a log record after trace-context has been added. This requires `disableLogCorrelation` to be false. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ export class BunyanInstrumentation extends InstrumentationBase<
return;
}
this._diag.debug('Adding OpenTelemetryBunyanStream to logger');
let currentLevel = logger.level();
let streamLevel = logger.level();
if (config.logSeverity) {
const bunyanLevel = bunyanLevelFromSeverity(config.logSeverity);
currentLevel = bunyanLevel || currentLevel;
streamLevel = bunyanLevel || streamLevel;
}
logger.addStream({
type: 'raw',
stream: new OpenTelemetryBunyanStream(),
level: currentLevel,
level: streamLevel,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ describe('BunyanInstrumentation', () => {
assert.strictEqual(rec.attributes.aProperty, 'bar');
});

it('log record level configuration', () => {
it('log record level configuration (higher than default)', () => {
instrumentation.setConfig({ logSeverity: SeverityNumber.WARN });

// Changing `disableLogSending` only has an impact on Loggers created
// Setting `logSeverity` only has an impact on Loggers created
// *after* it is set. So we cannot test with the `log` created in
// `beforeEach()` above.
log = Logger.createLogger({ name: 'test-logger-name', stream });
Expand All @@ -335,6 +335,17 @@ describe('BunyanInstrumentation', () => {
assert.strictEqual(logRecords.length, 1);
assert.strictEqual(logRecords[0].body, 'warn log');
});

it('log record level configuration (lower than default)', () => {
instrumentation.setConfig({ logSeverity: SeverityNumber.DEBUG });
log = Logger.createLogger({ name: 'test-logger-name', stream });
log.info('info log');
log.debug('debug log');
const logRecords = memExporter.getFinishedLogRecords();
// Only one log record match configured severity
assert.strictEqual(logRecords.length, 1);
assert.strictEqual(logRecords[0].body, 'debug log');
});
});

describe('disabled instrumentation', () => {
Expand Down

0 comments on commit fdce25c

Please sign in to comment.