The trace_id never change with fastify and fastify-redis using fastify.listen callback
Expected behaviour The trace_id should change every time a new http request is received.
Actual behaviour A new scope is activated during fastify startup and it will be used for all the next requests, so the trace_id never change.
Steps to reproduce
The following code is affected, running fastify with node index.js and making some request to http://0.0.0.0:3299/ shows that the trace_id in the logs never changes.
const tracer = require('dd-trace').init({
logInjection: true,
sampleRate: 1,
})
tracer.use('fastify', {
analytics: true,
blocklist: ['/alive'],
})
const fastify = require('fastify')
async function run() {
const app = fastify({
logger: true,
disableRequestLogging: false,
})
app.register(async (fastify, options, done) => {
fastify.register(require('fastify-redis'), {
namespace: 'redis',
host: '127.0.0.1',
port: 6379,
keyPrefix: 'datadog',
enableAutoPipelining: false,
lazyConnect: false
})
})
app.get('/', () => {
return { status: 'OK' }
})
// await app.listen(3299, '0.0.0.0')
app.listen(3299, '0.0.0.0', (err, call) => { })
}
run()
Running fastify with await app.listen(3299, '0.0.0.0') instead app.listen(3299, '0.0.0.0', (err, call) => { }) fix the issue and the trace_id start to change, as expected, on every request.
Another way to fix the issue is to change the lazyConnect to true during fastify-redis registration
Environment
- Node.js version: v16.15.1
- Tracer version: NO
- Agent version: NO
- Relevant library versions:
- dd-trace: v2.12.2
- fastify: v3.29.1
- fastify-redis: v4.3.2
{
"name": "debug-dd-trace",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dd-trace": "2.12.2",
"fastify": "3.29.1",
"fastify-redis": "4.3.2"
}
}