Introduce ContextualScopeManager#233
Conversation
7d67333 to
cc31bbe
Compare
|
|
||
| public class ContextualScopeManager implements ScopeManager { | ||
| final ThreadLocal<Scope> tlsScope = new ThreadLocal<>(); | ||
| final Set<ScopeContext> scopeContexts = new CopyOnWriteArraySet<>(); |
There was a problem hiding this comment.
Because we're iterating a list, ScopeContexts which were added earlier will have a chance to activate before later added ones. Do you think this is the correct behavior or should we consider using a stack based approach (i.e. give the most recently added scope managers a chance to activate first)?
There was a problem hiding this comment.
I thought about that... you're suggesting essentially reverse the order of iteration?
There was a problem hiding this comment.
Yes. I don't have a strong feeling about it, but that was my initial expectation.
There was a problem hiding this comment.
Can you think of a use case where that difference would be important? I'm open to the idea... this was just an area of the design I hadn't fully explored the implications of.
There was a problem hiding this comment.
My 2c, a predictable iteration order would be preferable when debugging something like this. In the Ratpack case, we might be integrating an external library such as rxJava and want to be providing a different scope in this case. Order of addition would be as good as any to determine the order. Stack ordering is most natural to me.
With the approach as here each ScopeContext might need to be aware of other ScopeContexts to deliver the correct scope (I can't think of a concrete case so I may be wrong).
There was a problem hiding this comment.
I've replaced it with a Deque.
realark
left a comment
There was a problem hiding this comment.
Looks good. I just have one comment.
|
@jonmort would you also mind taking a look? Think this would cover your use-case? |
jonmort
left a comment
There was a problem hiding this comment.
This looks to meet my use case for instrumenting Ratpack. I've not tried it (and I won't get to for at least a week as I'm off on vacation) but the approach looks flexible enough to accommodate all of the async cases I can think of. Nice work.
|
|
||
| public class ContextualScopeManager implements ScopeManager { | ||
| final ThreadLocal<Scope> tlsScope = new ThreadLocal<>(); | ||
| final Set<ScopeContext> scopeContexts = new CopyOnWriteArraySet<>(); |
There was a problem hiding this comment.
My 2c, a predictable iteration order would be preferable when debugging something like this. In the Ratpack case, we might be integrating an external library such as rxJava and want to be providing a different scope in this case. Order of addition would be as good as any to determine the order. Stack ordering is most natural to me.
With the approach as here each ScopeContext might need to be aware of other ScopeContexts to deliver the correct scope (I can't think of a concrete case so I may be wrong).
| } | ||
| } | ||
| if (span instanceof DDSpan && ((DDSpan) span).context().useRefCounting) { | ||
| return new RefCountingScope(this, new AtomicInteger(1), span); |
There was a problem hiding this comment.
The behaviour here appears to be different for the RefCountingScope with respect to finishOnClose. From what I see calling close() on RefCountingScope will always finish the scope.
There was a problem hiding this comment.
I've combined the two into a single Scope type. Now the span won't finish unless both ref counter is 0 and the boolean is true.
ca8f949 to
fd98cc1
Compare
eebc935 to
b52a939
Compare
Also added additional tests.
Rather than it just be a list of spans… This allows for tracking of if the trace was reported or not, and in the future to do so independently of finishing the span.
Wait until all spans are finished or garbage collected before reporting trace.
If all the current spans on a trace complete before a continuation can be activated, previously the trace could have been reported, not allowing additional spans to be added. This PR changes it so any created continuations must be dereferenced (GC’d) before allowing the trace to be reported.
to allow a completed trace to be reported more timely. Continuation is closed when the returned scope is closed, but can also be closed directly.
13c354a to
4fffb61
Compare
Still doesn’t work with Spring Boot because the way they structure their Jars.
To prevent errors on injected classes.
There've been quite a bit of changes since last review.
|
@tylerbenson Not yet. I'd like to get #255 merged in first. |
We expect customers to be using these also, so we can’t change them.
scala instrumentation
Implement the TraceInterceptor API
First pass design on having multiple kinds of ScopeManagers. Focus on naming and API design. See test for API usage... Still requires casting to some degree.
(Continuing from #223.)
Opening now so you have a chance to review today/tomorrow.