dd-trace-js
dd-trace-js copied to clipboard
Pino and dd-trace not working together
Expected behaviour Pino should integrate nicely with datadog Actual behaviour I'm seeing something similar to https://github.com/DataDog/dd-trace-js/issues/2189. Logs of pino do not include the datadog fields
Steps to reproduce
I'm using "dd-trace": "4.11.0"
and "pino": "8.14.2"
// index.ts
// Import tracer first thing so that pino can be hooked
import tracer from './metrics/Tracer.js';
// import { pino } from "pino";
(async function main () {
await tracer.trace('Some Trace', async () => {
console.log(tracer.scope().active())
const logger = pino({
} )
logger.info('Starting service...') })
})()
// Tracer.ts
import tracer from 'dd-trace'
// BTW, types are wrong here, it claims that tracer.init does not exist. I've also tried tracer.tracer.init(..) but same result as this bug
// @ts-ignore
tracer.init({
logInjection: true,
})
// also tried
/*
tracer.tracer.init({
logInjection: true,
})
*/
// Note that docs https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/nodejs/?tab=containers suggest exporting just tracer but that seems to break
export default tracer.tracer
This logs:
// DatadogSpan { ...
// {"level":30,"time":1691057718718,"pid":59863,"hostname":"mm","msg":"Starting service..."}
From the logs I can see that the scope of the tracer is defined. I'm even creating the logger inside the scope just for the testing.
Environment
- Operation system: Linux
- Node.js version: Node 18
-
Tracer version:
"dd-trace": "4.11.0"
- Agent version:
-
Relevant library versions:
"pino": "8.14.2"
BTW, with winston it does work. So I guess that all the hooks to datadog are in place
I'm seeing the exact same thing.
I think I know what is broken.
This works
import pino from "pino";
This does not work for log injection even though the pino logger itself still works.
import { pino } from "pino";
Don't ask me how many days it took to figure that out :)
@khanayan123 do you think this could be an ESM bug based on the comment that @ChrisBellew left?