Skip to content

Introduce ContextualScopeManager#233

Merged
realark merged 26 commits into
masterfrom
configurable-scope-manager
Mar 12, 2018
Merged

Introduce ContextualScopeManager#233
realark merged 26 commits into
masterfrom
configurable-scope-manager

Conversation

@tylerbenson
Copy link
Copy Markdown
Contributor

@tylerbenson tylerbenson commented Feb 16, 2018

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.

@tylerbenson tylerbenson added type: enhancement Enhancements and improvements tag: do not merge Do not merge changes type: feature request tag: community Community contribution labels Feb 16, 2018
@tylerbenson tylerbenson force-pushed the configurable-scope-manager branch from 7d67333 to cc31bbe Compare February 16, 2018 12:21

public class ContextualScopeManager implements ScopeManager {
final ThreadLocal<Scope> tlsScope = new ThreadLocal<>();
final Set<ScopeContext> scopeContexts = new CopyOnWriteArraySet<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that... you're suggesting essentially reverse the order of iteration?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I don't have a strong feeling about it, but that was my initial expectation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it with a Deque.

realark
realark previously approved these changes Feb 16, 2018
Copy link
Copy Markdown
Contributor

@realark realark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just have one comment.

@tylerbenson
Copy link
Copy Markdown
Contributor Author

@jonmort would you also mind taking a look? Think this would cover your use-case?

Copy link
Copy Markdown
Contributor

@jonmort jonmort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tylerbenson tylerbenson mentioned this pull request Feb 20, 2018
@tylerbenson
Copy link
Copy Markdown
Contributor Author

@realark @jonmort I resolved both of your concerns by replacing the CopyOnWriteArraySet with ConcurrentLinkedDeque. Priority is now given to the last added.

@tylerbenson tylerbenson force-pushed the configurable-scope-manager branch 3 times, most recently from ca8f949 to fd98cc1 Compare February 27, 2018 06:35
@tylerbenson tylerbenson added this to the 0.5.0 milestone Feb 28, 2018
@tylerbenson tylerbenson force-pushed the configurable-scope-manager branch from eebc935 to b52a939 Compare March 2, 2018 02:31
jonmort and others added 12 commits March 9, 2018 14:31
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.
@tylerbenson tylerbenson force-pushed the configurable-scope-manager branch from 13c354a to 4fffb61 Compare March 9, 2018 04:32
Still doesn’t work with Spring Boot because the way they structure their Jars.
To prevent errors on injected classes.
@tylerbenson tylerbenson dismissed realark’s stale review March 9, 2018 04:46

There've been quite a bit of changes since last review.

@tylerbenson
Copy link
Copy Markdown
Contributor Author

@palazzem @realark do we think this is ready to merge into master?

@realark
Copy link
Copy Markdown
Contributor

realark commented Mar 9, 2018

@tylerbenson Not yet. I'd like to get #255 merged in first.

@realark realark self-requested a review March 12, 2018 22:36
@realark realark merged commit 054ef0f into master Mar 12, 2018
@realark realark deleted the configurable-scope-manager branch March 12, 2018 22:38
@realark realark removed this from the 0.5.0 milestone Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: community Community contribution tag: do not merge Do not merge changes type: enhancement Enhancements and improvements type: feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants