Skip to content

Commit dadf308

Browse files
authored
test(instrumentation-pino): refactor Pino tests for correctness (open-telemetry#2247)
Before this change the 'PinoInstrumentation' was being created one or more times per test case, which results in the pino module getting wrapped *each* time. The pino instrumentation wraps the top-level/default export, so it cannot use the typical instrumentation._wrap along with isWrapped/unwrap handling. The result was a stack of pino() being wrapped over a dozen times, with each of those 'patchedPino's being active. This caused debugging complexity. For example, every test case after the logKeys test case would get span context fields being added as trace_id/span_id *and* traceId/spandId because the earlier PinoInstrumentation was still active. I suspect the 'pino-disabled.test.ts' tests were only working because they ran *first*, because 'disabled' luckily comes before 'enabled' alphabetically. This refactors the tests back to a single file (because mocha runs separate test files in the same process there is some cross-talk between the files), and works with a single instance of PinoInstrumentation. FWIW the instr-bunyan and instr-winston tests work similarly.
1 parent 93e7aab commit dadf308

File tree

6 files changed

+432
-520
lines changed

6 files changed

+432
-520
lines changed

package-lock.json

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/opentelemetry-instrumentation-pino/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
},
4646
"devDependencies": {
4747
"@opentelemetry/api": "^1.3.0",
48-
"@opentelemetry/context-async-hooks": "^1.8.0",
4948
"@opentelemetry/contrib-test-utils": "^0.40.0",
5049
"@opentelemetry/sdk-trace-base": "^1.8.0",
5150
"@opentelemetry/sdk-trace-node": "^1.8.0",

plugins/node/opentelemetry-instrumentation-pino/test/common.ts

-121
This file was deleted.

plugins/node/opentelemetry-instrumentation-pino/test/pino-disabled.test.ts

-86
This file was deleted.

0 commit comments

Comments
 (0)