Skip to content

Commit

Permalink
[DI] Clean up all logs emitted by the debugger (#5008)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson authored Dec 13, 2024
1 parent 4304684 commit 25d46fc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ async function addBreakpoint (probe) {
if (!script) throw new Error(`No loaded script found for ${file} (probe: ${probe.id}, version: ${probe.version})`)
const [path, scriptId] = script

log.debug(`Adding breakpoint at ${path}:${line} (probe: ${probe.id}, version: ${probe.version})`)
log.debug(
'[debugger:devtools_client] Adding breakpoint at %s:%d (probe: %s, version: %d)',
path, line, probe.id, probe.version
)

const { breakpointId } = await session.post('Debugger.setBreakpoint', {
location: {
Expand Down
4 changes: 3 additions & 1 deletion packages/dd-trace/src/debugger/devtools_client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const config = module.exports = {
updateUrl(parentConfig)

configPort.on('message', updateUrl)
configPort.on('messageerror', (err) => log.error('Debugger config messageerror', err))
configPort.on('messageerror', (err) =>
log.error('[debugger:devtools_client] received "messageerror" on config port', err)
)

function updateUrl (updates) {
config.url = updates.url || format({
Expand Down
5 changes: 4 additions & 1 deletion packages/dd-trace/src/debugger/devtools_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ session.on('Debugger.paused', async ({ params }) => {
await session.post('Debugger.resume')
const diff = process.hrtime.bigint() - start // TODO: Recored as telemetry (DEBUG-2858)

log.debug(`Finished processing breakpoints - main thread paused for: ${Number(diff) / 1000000} ms`)
log.debug(
'[debugger:devtools_client] Finished processing breakpoints - main thread paused for: %d ms',
Number(diff) / 1000000
)

// Due to the highly optimized algorithm above, the `probes` array might have gaps
probes = probes.filter((probe) => !!probe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ rcPort.on('message', async ({ action, conf: probe, ackId }) => {
ackError(err, probe)
}
})
rcPort.on('messageerror', (err) => log.error('Debugger RC message error', err))
rcPort.on('messageerror', (err) => log.error('[debugger:devtools_client] received "messageerror" on RC port', err))

async function processMsg (action, probe) {
log.debug(`Received request to ${action} ${probe.type} probe (id: ${probe.id}, version: ${probe.version})`)
log.debug(
'[debugger:devtools_client] Received request to %s %s probe (id: %s, version: %d)',
action, probe.type, probe.id, probe.version
)

if (action !== 'unapply') ackReceived(probe)

Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/debugger/devtools_client/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ackEmitting ({ id: probeId, version }) {
}

function ackError (err, { id: probeId, version }) {
log.error('Debugger ackError', err)
log.error('[debugger:devtools_client] ackError', err)

onlyUniqueUpdates(STATUSES.ERROR, probeId, version, () => {
const payload = statusPayload(probeId, version, STATUSES.ERROR)
Expand Down Expand Up @@ -87,7 +87,7 @@ function send (payload) {
}

request(form, options, (err) => {
if (err) log.error('Error sending debugger payload', err)
if (err) log.error('[debugger:devtools_client] Error sending debugger payload', err)
})
}

Expand Down
16 changes: 8 additions & 8 deletions packages/dd-trace/src/debugger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
function start (config, rc) {
if (worker !== null) return

log.debug('Starting Dynamic Instrumentation client...')
log.debug('[debugger] Starting Dynamic Instrumentation client...')

const rcAckCallbacks = new Map()
const rcChannel = new MessageChannel()
Expand All @@ -33,14 +33,14 @@ function start (config, rc) {
const ack = rcAckCallbacks.get(ackId)
if (ack === undefined) {
// This should never happen, but just in case something changes in the future, we should guard against it
log.error('Received an unknown ackId: %s', ackId)
if (error) log.error('Error starting Dynamic Instrumentation client', error)
log.error('[debugger] Received an unknown ackId: %s', ackId)
if (error) log.error('[debugger] Error starting Dynamic Instrumentation client', error)
return
}
ack(error)
rcAckCallbacks.delete(ackId)
})
rcChannel.port2.on('messageerror', (err) => log.error('Debugger RC messageerror', err))
rcChannel.port2.on('messageerror', (err) => log.error('[debugger] received "messageerror" on RC port', err))

worker = new Worker(
join(__dirname, 'devtools_client', 'index.js'),
Expand All @@ -58,16 +58,16 @@ function start (config, rc) {
)

worker.on('online', () => {
log.debug(`Dynamic Instrumentation worker thread started successfully (thread id: ${worker.threadId})`)
log.debug('[debugger] Dynamic Instrumentation worker thread started successfully (thread id: %d)', worker.threadId)
})

worker.on('error', (err) => log.error('Debugger worker error', err))
worker.on('messageerror', (err) => log.error('Debugger worker messageerror', err))
worker.on('error', (err) => log.error('[debugger] worker thread error', err))
worker.on('messageerror', (err) => log.error('[debugger] received "messageerror" from worker', err))

worker.on('exit', (code) => {
const error = new Error(`Dynamic Instrumentation worker thread exited unexpectedly with code ${code}`)

log.error('Debugger worker exited unexpectedly', error)
log.error('[debugger] worker thread exited unexpectedly', error)

// Be nice, clean up now that the worker thread encounted an issue and we can't continue
rc.removeProductHandler('LIVE_DEBUGGING')
Expand Down

0 comments on commit 25d46fc

Please sign in to comment.