Skip to content

Commit 34499f3

Browse files
authored
[DI] Ensure probe EMITTING status is sent correctly (#5133)
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.
1 parent 307f471 commit 34499f3

3 files changed

Lines changed: 6 additions & 27 deletions

File tree

packages/dd-trace/src/debugger/devtools_client/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ session.on('Debugger.paused', async ({ params }) => {
146146
}
147147
}
148148

149+
ackEmitting(probe)
149150
// TODO: Process template (DEBUG-2628)
150-
send(probe.template, logger, dd, snapshot, () => {
151-
ackEmitting(probe)
152-
})
151+
send(probe.template, logger, dd, snapshot)
153152
}
154153
})
155154

packages/dd-trace/src/debugger/devtools_client/send.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ const ddtags = [
2929

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

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

35-
function send (message, logger, dd, snapshot, cb) {
34+
function send (message, logger, dd, snapshot) {
3635
const payload = {
3736
ddsource,
3837
hostname,
@@ -58,7 +57,6 @@ function send (message, logger, dd, snapshot, cb) {
5857
}
5958

6059
jsonBuffer.write(json, size)
61-
callbacks.push(cb)
6260
}
6361

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

72-
const _callbacks = callbacks
73-
callbacks = []
74-
7570
request(payload, opts, (err) => {
7671
if (err) log.error('[debugger:devtools_client] Error sending probe payload', err)
77-
else _callbacks.forEach(cb => cb())
7872
})
7973
}

packages/dd-trace/test/debugger/devtools_client/send.spec.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ describe('input message http requests', function () {
5454
})
5555

5656
it('should call request with the expected payload once the buffer is flushed', function (done) {
57-
const callback1 = sinon.spy()
58-
const callback2 = sinon.spy()
59-
const callback3 = sinon.spy()
60-
61-
send({ message: 1 }, logger, dd, snapshot, callback1)
62-
send({ message: 2 }, logger, dd, snapshot, callback2)
63-
send({ message: 3 }, logger, dd, snapshot, callback3)
57+
send({ message: 1 }, logger, dd, snapshot)
58+
send({ message: 2 }, logger, dd, snapshot)
59+
send({ message: 3 }, logger, dd, snapshot)
6460
expect(request).to.not.have.been.called
6561

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

86-
expect(callback1).to.not.have.been.calledOnce
87-
expect(callback2).to.not.have.been.calledOnce
88-
expect(callback3).to.not.have.been.calledOnce
89-
90-
request.firstCall.callback()
91-
92-
expect(callback1).to.have.been.calledOnce
93-
expect(callback2).to.have.been.calledOnce
94-
expect(callback3).to.have.been.calledOnce
95-
9682
done()
9783
})
9884
})

0 commit comments

Comments
 (0)