Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweaks to ckozak's DetachedSpan & demo usage #247

Merged
merged 29 commits into from
Sep 2, 2019

Conversation

iamdanfox
Copy link
Contributor

@iamdanfox iamdanfox commented Aug 30, 2019

Before this PR

In conjure-java-runtime and dialogue, we want to be able to measure a span of time beginning on one thread and ending on another (e.g. backoffs or client-side concurrency limits). We do have an AsyncTracer class already, but this makes two spans: <operation>-enqueue and <operation>-run.

After this PR

A new CrossThreadSpan class allows measuring operations that begin on one thread and end on another.

I'm not expecting this to be used by regular service authors much, but hoping we can benefit from it in our libraries.

image

Possible downsides?

TODO

@iamdanfox iamdanfox requested a review from a team as a code owner August 30, 2019 11:26
@changelog-app
Copy link

changelog-app bot commented Aug 30, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

A new CrossThreadSpan class allows measuring operations that begin on one thread and end on another.

Check the box to generate changelog(s)

  • Generate changelog entry

@iamdanfox iamdanfox changed the title CrossThreadTracing CrossThreadSpans Aug 30, 2019
: Tracer.createTrace(Observability.UNDECIDED, Tracers.randomId());

Optional<String> parentSpanId = trace.top().map(OpenSpan::getSpanId);
OpenSpan openSpan1 = OpenSpan.of(
Copy link
Contributor

Choose a reason for hiding this comment

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

openSpan1 -> openSpan?


Map<String, String> metadata = Collections.emptyMap();
Span span = Tracer.toSpan(inProgress, metadata, traceId);
Tracer.notifyObservers(span);
Copy link
Contributor

Choose a reason for hiding this comment

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

it'd be nice to pull lines 85-89 and 70-76 into a common private function


// we throw away the existing thread local state and replace it with our view of the world
Tracer.clearCurrentTrace();
Tracer.setTrace(Trace.of(observable, traceId));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe I'd wrap up the clearCurrentTrace+setTrace into a couple a private method replaceTraceState that takes no args, you can reuse it in child, too

}

/**
* Unusual method - returns a new {@link CrossThreadSpan} parented to this instance. Only necessary if you want
Copy link
Contributor

Choose a reason for hiding this comment

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

would be helpful to include an example in the docs of when to use this, it's not obvious how to select child or this method, both result in a parented CrossThreadSpan?

@markelliot
Copy link
Contributor

@jellis curious if this works for your needs?

@ferozco ferozco changed the base branch from develop to ckozak/detached_tracing_api August 30, 2019 15:44
@iamdanfox iamdanfox changed the title CrossThreadSpans tweaks to ckozak's DetachedSpan & demo usage Aug 30, 2019
@iamdanfox
Copy link
Contributor Author

Ok so this is just gonna land into the existing DetachedSpan branch - I think it will let us do all the tracing we want in c-j-r. Hope the names look OK from your perspective @carterkozak?

Definitely still want to explore Mark's new internal representation ideas, but don't want to block this PR on that (as it should be easy to polyfill later if we need to).

@@ -21,10 +21,10 @@
/**
* Closeable marker around a tracing span operation. This object should be used in a try/with block.
*/
public interface SpanToken extends Closeable {
public interface CloseableSpan extends Closeable {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I like this better.

@carterkozak
Copy link
Contributor

👍

1 similar comment
@ferozco
Copy link
Contributor

ferozco commented Aug 31, 2019

👍

@bulldozer-bot bulldozer-bot bot merged commit bc20b95 into ckozak/detached_tracing_api Sep 2, 2019
@bulldozer-bot bulldozer-bot bot deleted the dfox/cross-thread-tracing branch September 2, 2019 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants