-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make zipkin's current context can be nested
Apply this change will fix TraceContext leak in thread problem. There is a case that we keep armeria's request context aware CompletableFuture for fetching data, and let multiple request register callback on that future. So there is a problem that future uses first request's eventloop and RequestContext to call waiting handlers, but each handler may wrap with it's RequestContext, so there is nested RequestContext on same thread(onEnter->onEnter->onExit->onExit). Another solution is application developer should always jump back to current request's context aware eventloop. e.g. ``` cachedFuture.acceptAsync((r, e)->{ ... }, RequestContext.current.contextAwareEventloop); ``` I'm not sure if armeria side need to take care of this or not...
- Loading branch information
Showing
4 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
zipkin/src/main/java/com/linecorp/armeria/internal/tracing/SpanInScopeWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.linecorp.armeria.internal.tracing; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import brave.Tracer.SpanInScope; | ||
|
||
/** | ||
* SpanInScope Wrapper for keeping previous span scope. | ||
*/ | ||
public final class SpanInScopeWrapper implements AutoCloseable { | ||
|
||
private final SpanInScope spanInScope; | ||
|
||
@Nullable | ||
private final SpanInScopeWrapper previous; | ||
|
||
public SpanInScopeWrapper(SpanInScope current, @Nullable SpanInScopeWrapper previous) { | ||
this.spanInScope = current; | ||
this.previous = previous; | ||
} | ||
|
||
@Nullable | ||
public SpanInScopeWrapper getPrevious() { | ||
return previous; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
spanInScope.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters