Skip to content

Commit

Permalink
limit log-sending to pino@7 and later because that's when pino.multis…
Browse files Browse the repository at this point in the history
…tream was added
  • Loading branch information
trentm committed May 30, 2024
1 parent be12617 commit 899f153
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions plugins/node/opentelemetry-instrumentation-pino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm install --save @opentelemetry/instrumentation-pino
### Supported versions

- `pino` versions `>=5.14.0 <10`
- The "log sending" feature is only supported in pino v7 and later.

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class PinoInstrumentation extends InstrumentationBase {
}

// Setup "log sending" -- sending log records to the Logs API.
if (isEnabled && !config.disableLogSending) {
// This depends on `pino.multistream`, which was added in v7.0.0.
if (isEnabled && !config.disableLogSending && typeof moduleExports.multistream === 'function') {
const otelTimestampFromTime = getTimeConverter(
logger,
moduleExports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ describe('PinoInstrumentation', () => {
assert.strictEqual(record['span_id'], undefined);
assert.strictEqual(record['trace_flags'], undefined);
assert.strictEqual(record['resource.service.name'], undefined);

assert.strictEqual(
memExporter.getFinishedLogRecords().length,
1,
'Log sending still works'
);
});
});

Expand Down Expand Up @@ -404,6 +398,12 @@ describe('PinoInstrumentation', () => {
let stream: Writable;
let writeSpy: sinon.SinonSpy;

before(function () {
if (typeof pino.multistream !== 'function') {
this.skip();
}
})

beforeEach(() => {
instrumentation.setConfig({}); // reset to defaults
memExporter.getFinishedLogRecords().length = 0; // clear
Expand Down

0 comments on commit 899f153

Please sign in to comment.