Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions utils/build/docker/nodejs/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ app.get('/', (req, res) => {
res.send('Hello world!\n')
})

app.get('/spawn_child', (req, res) => {
const path = require('path')
const { spawn, fork } = require('child_process')
const sleep = req.query.sleep != null ? String(req.query.sleep) : null
const crash = req.query.crash
if (sleep == null || sleep === '') {
res.status(400).send('sleep required')
return
}
const crashStr = String(crash || '').toLowerCase()
const forkStr = String(req.query.fork || '').toLowerCase()
if (crashStr !== 'true' && crashStr !== 'false') {
res.status(400).send('crash required (boolean)')
return
}
if (forkStr !== 'true' && forkStr !== 'false') {
res.status(400).send('fork required (boolean)')
return
}
const useFork = forkStr === 'true'
const childScript = path.join(__dirname, 'fork_child.js')

if (useFork) {
const child = fork(childScript, [sleep, crashStr])
child.on('close', (code, signal) => {
res.send(`Child process ${child.pid} exited with code ${code}, signal ${signal}`)
})
} else {
const child = spawn(process.execPath, [childScript, sleep, crashStr], { stdio: 'inherit' })
child.on('close', (code, signal) => {
res.send(`Child process ${child.pid} exited with code ${code}, signal ${signal}`)
})
}
})

app.get('/healthcheck', (req, res) => {
res.json({
status: 'ok',
Expand Down
11 changes: 11 additions & 0 deletions utils/build/docker/nodejs/express/fork_child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
// Child process for spawn_child endpoint. Args: sleep (seconds), crash (true|false).
const sleepSec = parseInt(process.argv[2] || '2', 10) * 1000
Comment on lines +1 to +3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preload dd-trace in the spawned child process

In the express4/express5/uds-express4 images I checked (utils/build/docker/nodejs/express4.Dockerfile, utils/build/docker/nodejs/express5.Dockerfile, and utils/build/docker/nodejs/app.sh), the weblog is started as node app.js and never sets NODE_OPTIONS/--require dd-trace. Because this child script only sleeps and exits, both the new fork() and spawn() paths will launch an uninstrumented Node process, so the session-ID header tests this endpoint is meant to support will not observe any child telemetry or DD-Session-ID/DD-Root-Session-ID headers on the standard express weblogs.

Useful? React with 👍 / 👎.

const crash = process.argv[3] === 'true'
setTimeout(() => {
if (crash) {
process.kill(process.pid, 'SIGSEGV')
} else {
process.exit(0)
}
}, sleepSec)
Loading