Skip to content

Commit 2882bc8

Browse files
authored
Merge pull request #1100 from microsoft/trask/fix-async-thread-tracking
Fix async thread tracking
2 parents 9e20a2f + 77d91cc commit 2882bc8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/model/AuxThreadContextImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public Span startAndMarkAsyncTransactionComplete() {
5353
private Span start(boolean completeAsyncTransaction) {
5454
ThreadContextThreadLocal.Holder threadContextHolder = Global.getThreadContextHolder();
5555
ThreadContextPlus threadContext = threadContextHolder.get();
56-
if (threadContext != null) {
56+
// TODO once local spans are supported, only return NOP if parent spans are the same
57+
// Checking if in same request is needed in case the existing thread context is from a prior request
58+
// (e.g. this can happen if the thread activity was captured via Thread constructor, but the thread was
59+
// really then used in a thread pool)
60+
if (threadContext != null && threadContext.getServletRequestInfo() == servletRequestInfo) {
5761
if (completeAsyncTransaction) {
5862
threadContext.setTransactionAsyncComplete();
5963
}

0 commit comments

Comments
 (0)