pino-instrumentation not injecting trace_id into logs when used with TypeScript
See original GitHub issueWhat version of OpenTelemetry are you using?
"@opentelemetry/auto-instrumentations-node": "^0.25.0",
"@opentelemetry/core": "^1.0.1",
"@opentelemetry/exporter-collector": "^0.24.0",
"@opentelemetry/exporter-prometheus": "^0.18.2",
"@opentelemetry/instrumentation": "^0.24.0",
"@opentelemetry/instrumentation-pino": "^0.28.1",
"@opentelemetry/metrics": "^0.18.2",
"@opentelemetry/node": "^0.24.0",
"@opentelemetry/propagator-b3": "^1.0.0",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/sdk-trace-node": "^1.0.1",
"@opentelemetry/semantic-conventions": "^1.0.0",
"pino": "^7.6.4",
"express": "^4.17.1",
"my-logger": "file: ../my-logger"
What version of Node are you using?
v16.6.1
What did you do?
“my-logger” is a separate typescript project on my machine, here is the simple implementation which instantiates an instance of pino and exports as default. https://gist.github.com/armandAkop/3e064c2e378cdd8a442b339f3b5e28f6
I am running “tsc” in the repo and outputting the transpiled file to “dist/index.js”, which contains
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const pino_1 = require("pino");
const logger = pino_1.pino;
exports.default = (0, pino_1.pino)();
//# sourceMappingURL=index.js.map
Here is the script I am testing with auto-instrumentation-node and pino-instrumentation. This script lives in a folder called project-A and has a local reference to “my-logger” project on line 157 https://gist.github.com/armandAkop/d2fb6f806b31b6844262918489bf0679
What did you expect to see?
I expected my test scripts log entry to contain the trace_id field
What did you see instead?
trace_id is not present in the log message. When I change the my-logger project to be a regular Javascript project with an index.js which looks like
module.exports = require('pino')();
AND changed package.json to “main” property to “main”: “index.js”
The trace_id appears in the log as expected
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (10 by maintainers)
Top Related StackOverflow Question
Ported to typescript and there seems to be a bug in the instrumentation resulting in non working setups depending on how you import and if esModuleInterop is set in tsconfig.js. see below for details.
root cause is that pino exports itself several times:
const pino = require('pino')pinoproperty on the export (case `import { pino } from ‘pino’)defaultproperty on the export (not sure when this is used, maybe byimport pino from 'pino'ifesModuleInterop: false)The instrumentation covers only the first case above.
We don’t have a component owner for the pino instrumentation, but it was contributed by @seemk. Would you care to take a look, Siim?