Skip to content

Commit

Permalink
[DI] Ensure probe EMITTING status is sent correctly
Browse files Browse the repository at this point in the history
Queue the probe EMITTING status before trying to queue the probe
payload.

Before, the EMITTING status was only emitted if the probe payload was
successfully received by the agnet. If the agent didn't return a HTTP
2xx status code, the EMITTING status would never be sent.
  • Loading branch information
watson committed Jan 19, 2025
1 parent 307f471 commit b12d02a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
5 changes: 2 additions & 3 deletions packages/dd-trace/src/debugger/devtools_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ session.on('Debugger.paused', async ({ params }) => {
}
}

ackEmitting(probe)
// TODO: Process template (DEBUG-2628)
send(probe.template, logger, dd, snapshot, () => {
ackEmitting(probe)
})
send(probe.template, logger, dd, snapshot)
}
})

Expand Down
8 changes: 1 addition & 7 deletions packages/dd-trace/src/debugger/devtools_client/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ const ddtags = [

const path = `/debugger/v1/input?${stringify({ ddtags })}`

let callbacks = []
const jsonBuffer = new JSONBuffer({ size: config.maxTotalPayloadSize, timeout: 1000, onFlush })

function send (message, logger, dd, snapshot, cb) {
function send (message, logger, dd, snapshot) {
const payload = {
ddsource,
hostname,
Expand All @@ -58,7 +57,6 @@ function send (message, logger, dd, snapshot, cb) {
}

jsonBuffer.write(json, size)
callbacks.push(cb)
}

function onFlush (payload) {
Expand All @@ -69,11 +67,7 @@ function onFlush (payload) {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}

const _callbacks = callbacks
callbacks = []

request(payload, opts, (err) => {
if (err) log.error('[debugger:devtools_client] Error sending probe payload', err)
else _callbacks.forEach(cb => cb())
})
}
20 changes: 3 additions & 17 deletions packages/dd-trace/test/debugger/devtools_client/send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ describe('input message http requests', function () {
})

it('should call request with the expected payload once the buffer is flushed', function (done) {
const callback1 = sinon.spy()
const callback2 = sinon.spy()
const callback3 = sinon.spy()

send({ message: 1 }, logger, dd, snapshot, callback1)
send({ message: 2 }, logger, dd, snapshot, callback2)
send({ message: 3 }, logger, dd, snapshot, callback3)
send({ message: 1 }, logger, dd, snapshot)
send({ message: 2 }, logger, dd, snapshot)
send({ message: 3 }, logger, dd, snapshot)
expect(request).to.not.have.been.called

expectWithin(1200, () => {
Expand All @@ -83,16 +79,6 @@ describe('input message http requests', function () {
`git.repository_url%3A${repositoryUrl}`
)

expect(callback1).to.not.have.been.calledOnce
expect(callback2).to.not.have.been.calledOnce
expect(callback3).to.not.have.been.calledOnce

request.firstCall.callback()

expect(callback1).to.have.been.calledOnce
expect(callback2).to.have.been.calledOnce
expect(callback3).to.have.been.calledOnce

done()
})
})
Expand Down

0 comments on commit b12d02a

Please sign in to comment.