Skip to content

Commit

Permalink
fix: obviously sync spans are not sent as sync
Browse files Browse the repository at this point in the history
Fixes #1878
  • Loading branch information
trentm committed Nov 17, 2020
1 parent 289ec42 commit b897c81
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/instrumentation/async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ module.exports = function (ins) {
// type, which will init for each scheduled timer.
if (type === 'TIMERWRAP') return

// XXX
// debug(`${type}(${asyncId}): trigger: ${triggerAsyncId}`);

const transaction = ins.currentTransaction
if (!transaction) return

Expand All @@ -91,6 +94,7 @@ module.exports = function (ins) {
function before (asyncId) {
const span = activeSpans.get(asyncId)
if (span) {
debug(`setting span.sync=false on span.id==${span.id} with span.ended==${span.ended}`)
span.sync = false
}
const transaction = span ? span.transaction : activeTransactions.get(asyncId)
Expand All @@ -116,3 +120,9 @@ module.exports = function (ins) {
activeSpans.delete(asyncId)
}
}

var fs = require('fs');
function debug(msg) {
fs.writeSync(process.stdout.fd,
`[executionAsyncId=${asyncHooks.executionAsyncId()}] ${msg}\n`);
}
16 changes: 16 additions & 0 deletions test/instrumentation/async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ test('sync/async tracking', function (t) {
})
})

test.only('sync/async tracking 2', function (t) {
var trans = agent.startTransaction()

var span = agent.startSpan()
t.strictEqual(span.sync, true, 'span.sync=true immediately after creation')

span.end()
t.strictEqual(span.sync, true, 'span.sync=true immediately after end')

setImmediate(() => {
t.strictEqual(span.sync, true,
'span.sync=true later after having ended sync')
t.end()
})
})

function twice (fn) {
setImmediate(fn)
setImmediate(fn)
Expand Down

0 comments on commit b897c81

Please sign in to comment.