Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/instrumentation/async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ module.exports = function (ins) {
}

function before (asyncId) {
const span = activeSpans.get(asyncId)
if (span) {
span.sync = false
}
const transaction = span ? span.transaction : activeTransactions.get(asyncId)
if (transaction) {
transaction.sync = false
}
ins.bindingSpan = null
}

Expand Down
14 changes: 14 additions & 0 deletions test/instrumentation/async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ test('post-defined, post-resolved promise', function (t) {
})
})

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

var span = agent.startSpan()
t.equal(span.sync, true)

setImmediate(() => {
t.equal(trans.sync, false)
t.equal(span.sync, false)
t.end()
})
})

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