Skip to content

Commit 999bfb6

Browse files
simon-idrochdev
authored andcommitted
fix: endpoint telemetry use setTimeout (#7298)
1 parent 5688f22 commit 999bfb6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/dd-trace/src/telemetry/endpoints.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function endpointKey (method, path) {
2929
function scheduleFlush () {
3030
if (flushScheduled) return
3131
flushScheduled = true
32-
setImmediate(flushAndSend).unref()
32+
// this used to be setImmediate() instead, but it was making the system test flaky
33+
// don't ask me why
34+
setTimeout(flushAndSend).unref()
3335
}
3436

3537
function recordEndpoint (method, path, operationName) {

packages/dd-trace/test/telemetry/endpoints.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const dc = require('dc-polyfill')
1010
const { assertObjectContains } = require('../../../../integration-tests/helpers')
1111
require('../setup/core')
1212

13-
const originalSetImmediate = global.setImmediate
13+
const originalSetTimeout = global.setTimeout
1414

1515
describe('endpoints telemetry', () => {
1616
const fastifyRouteCh = dc.channel('apm:fastify:route:added')
@@ -61,7 +61,7 @@ describe('endpoints telemetry', () => {
6161
'./send-data': { sendData }
6262
})
6363
scheduledCallbacks = []
64-
global.setImmediate = function (callback) {
64+
global.setTimeout = function (callback) {
6565
scheduledCallbacks.push(callback)
6666
return { unref () {} }
6767
}
@@ -83,7 +83,7 @@ describe('endpoints telemetry', () => {
8383
sendData.reset()
8484
getRetryData.reset()
8585
updateRetryData.reset()
86-
global.setImmediate = originalSetImmediate
86+
global.setTimeout = originalSetTimeout
8787
})
8888

8989
it('should not fail with invalid data', () => {

0 commit comments

Comments
 (0)