Skip to content

tweaks to ckozak's DetachedSpan & demo usage - #247

Merged
bulldozer-bot[bot] merged 29 commits into
ckozak/detached_tracing_apifrom
dfox/cross-thread-tracing
Sep 2, 2019
Merged

tweaks to ckozak's DetachedSpan & demo usage#247
bulldozer-bot[bot] merged 29 commits into
ckozak/detached_tracing_apifrom
dfox/cross-thread-tracing

Conversation

@iamdanfox

@iamdanfox iamdanfox commented Aug 30, 2019

Copy link
Copy Markdown
Contributor

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

changelog-app Bot commented Aug 30, 2019

Copy link
Copy Markdown

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

* 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
Copy Markdown
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
Copy Markdown
Contributor

👍

1 similar comment
@ferozco

ferozco commented Aug 31, 2019

Copy link
Copy Markdown
Contributor

👍

@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