Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

An RFC for SpanContext, References, as well as changes to carriers #32

Merged
merged 11 commits into from
Jul 15, 2016

Conversation

bhs
Copy link
Contributor

@bhs bhs commented Jul 13, 2016

I would love feedback about the API here... once we converge, we can decide what to do about the rest of this (github) repo (the impl helpers, etc).

Please look at #31 and opentracing/opentracing.io#99 for background and motivation.

I'll add a few PR comments inline as well.

* @see io.opentracing.Tracer#inject(SpanContext, Format, Object)
* @see io.opentracing.Tracer#extract(Format, Object)
*/
public class BuiltinFormats<R, W> implements Format<R, W> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yurishkuro I went with BuiltinFormats instead of Formats -- seemed to better emphasize that non-builtin extensions were feasible.

* undefined behavior.
*/
void finish();
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(indenting was off throughout this file)


/**
* BuiltinFormats encapsulates the inject()/extract() carrier formats that all Tracer implementations must support.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

probably worth it to add docs for these generic params.. like..

 * @param <R> foo used by {@link foo#bar} to bar things
 * @param <W> baz used by {@link baz#qux} to qux things

@michaelsembwever
Copy link
Contributor

Without the Format stuff from #31 i'm +1 on merging.

With the Format stuff it's currently a -1 from me, unless further discussion helps me see the light.

private Type type;
private SpanContext referee;

public enum Type {
Copy link
Member

@yurishkuro yurishkuro Jul 13, 2016

Choose a reason for hiding this comment

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

I am ok with this being an enum, as a list of build-in reference types, but the type field in the Reference class needs to be of a comparable type, not this enum. Otherwise this is not extensible without OT API release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we talked about this briefly off github -- I've gone with Comparable where reference types are needed and am using Strings for the builtin ones.

@bhs
Copy link
Contributor Author

bhs commented Jul 13, 2016

Meta-comment: I'm going to try and split the (controversial) Format stuff out of this PR inasmuch as that's possible. We can then talk about the SpanContext and Reference aspects in isolation. I'll try to make those changes in the next 4 hours or so.

The big picture in this commit:
- Get rid of the contentious stuff around Format for this PR
- Just define reference *types*; no need for a Reference class given
  Java's SpanBuilder approach
- Add an HttpHeader* carrier so we can discuss that properly
- Cleanups
@bhs
Copy link
Contributor Author

bhs commented Jul 14, 2016

Thanks so much for the comments, all, PTAL.

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Jul 14, 2016

my non-binding opinion is that the type complexity of Format<R, W> isn't worth putting into the base api. It would end up being wrapped I think.

Complex apis in java usually breed libraries that hide their complexity. If we want to avoid some side-project called OpenTracing-Lite, I'd suggest highly that we simplify as much as possible the front-door of this api.

*/
SpanBuilder withParent(Span parent);
SpanBuilder addReference(Comparable referenceType, SpanContext referencedContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

if using Comparable, we should provide rationale for the choice, for example, why ordering matters. It is distracting otherwise.

A guess is that we are expecting an implementation to have multiple parents and need to know the parent vs adopted vs step-parent? I suppose we are expecting the implementation to retain the order?

Another note, Comparable has a type parameter <T> which would lead to this method having a compiler warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll just change to Object. I was responding to an earlier comment about the downside of using the (now obliterated) Reference.Type enum, as enums by definition are not externally extensible. I don't think the use case for a global ordering nearly compelling enough... we really just want equality comparisons.

Copy link
Contributor

Choose a reason for hiding this comment

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

*/
SpanBuilder withParent(Span parent);
SpanBuilder addReference(Object referenceType, SpanContext referencedContext);

Choose a reason for hiding this comment

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

I understand reference types need to be extensible, but is there a need to make them arbitrary types? Why not String?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If all we need is equals(), I guess I would ask why String?

Copy link

@tinkerware tinkerware Jul 14, 2016

Choose a reason for hiding this comment

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

If we had a Symbol type in Java, it would be that. Failing that, isn't it better that we at least pick something that can be switch'ed on and has value semantics?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a String now.

@bhs
Copy link
Contributor Author

bhs commented Jul 14, 2016

@adriancole @michaelsembwever @yurishkuro @tinkerware

Since the (controversial) Format stuff has been split off from this PR, are there any objections to the remaining content? It seemed like we'd converged on the SpanContext / Reference / extract() aspects presented here.

I'm presently fixing the rest of the (github) repo to work along with these changes... it does require some surgery here and there but most of the diff will be uncontroversial. It's also far less important since OT callers don't depend on any of the impl helpers directly, of course.

Setting expectations: I'd like to merge this PR in 24-36h or so unless substantial new issues are raised.

*/
<T> void inject(Span span, T carrier);
<C> void inject(SpanContext spanContext, C carrier);

Choose a reason for hiding this comment

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

What's the point to the C type parameter when it does not constrain anything? If we are saying that a more elaborate format API is later work, we can just leave the carrier type Object for now, though it seems to me that there could at least be a marker interface for carriers.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, this C makes it look like there's more to the carrier type than just an Object. +1 to drop it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was inherited from the code at master...

https://github.com/opentracing/opentracing-java/blob/master/opentracing-api/src/main/java/io/opentracing/Tracer.java#L53

Aside from making the documentation more explicit (@param <C> ...), I can't provide any particular justification. I think this is code @michaelsembwever wrote, so I might be missing part of the rationale. (The documentation aspect is not trivial, though...)

Copy link
Contributor

Choose a reason for hiding this comment

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

It helps implementations. See AbstractTracer for example.
It also creates a stub to explain Carrier types.

No biggie either way for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tinkerware
Copy link

This seems okay to me, assuming that carrier/format API is not in its final form.


Span http = tracer.buildSpan("HandleHTTPRequest")
.withParent(feed)
.asChildOf(parentSpan.context())
Copy link
Member

Choose a reason for hiding this comment

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

@bensigelman similar to Node/Python, we can overload this to asChildOf(parentSpan)

@yurishkuro
Copy link
Member

lgtm

@michaelsembwever
Copy link
Contributor

👍

* @return the value of the baggage item identified by the given key, or null if no such item could be found
*/
String getBaggageItem(String key);
}

Choose a reason for hiding this comment

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

In go a method to iterate through all baggage items were introduced. Should you have it here as well ?

Copy link
Contributor Author

@bhs bhs Jul 15, 2016

Choose a reason for hiding this comment

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

I would like this to happen in a followup... there are some subtleties that you brought up re immutability that I think are relevant here (namely, if we know that SpanContexts are immutable, the interface can be zero-copy and return an iterator and be threadsafe... otherwise I'd rather do something like what we did in Go and have the SpanContext impl invoke a callback repeatedly).

(ed: I misremembered and thought tinkerware had brought up the immutability issue -- it was @dawallin!)

Ben Sigelman added 2 commits July 14, 2016 21:26
Much of the opentracing-impl stuff is dated to when we separated tracer
state and baggage. I've removed some of it and I think an argument could
be made to get rid of the rest, here, too; or maybe turn it into
basictracer-java or similar.
Make AbstractSpan abstract again (i.e., let subclasses handle
context()).
@bhs bhs force-pushed the bhs/span_context_etc branch from a72e548 to ff2d9ff Compare July 15, 2016 04:27
@bhs
Copy link
Contributor Author

bhs commented Jul 15, 2016

Okay -- I changed a bunch of stuff and fixed the build and tests in the rest of this repo (including NoopTracer, which is probably the only part anyone actually uses at this point).

*
* @return the SpanContext that encapsulates Span state that should propagate across process boundaries.
*/
SpanContext getContext();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to getContext() since this is Java :)

(I'd internalized Go's no-get getter convention, I guess)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@bhs
Copy link
Contributor Author

bhs commented Jul 15, 2016

(and if there are no further concerns, I will merge this sometime tomorrow)

@bhs bhs force-pushed the bhs/span_context_etc branch from 0e5a342 to 623db61 Compare July 15, 2016 15:39
@bhs
Copy link
Contributor Author

bhs commented Jul 15, 2016

@adriancole I dropped the getContext() commit. Thanks for the history lesson, too. :)

@bhs
Copy link
Contributor Author

bhs commented Jul 15, 2016

Okay, as promised, I'm merging this now. Thanks for all of the feedback.

#31 and opentracing/opentracing.io#106 are still open and could impact this API going forward.

@bhs bhs merged commit b0d7b07 into master Jul 15, 2016
@bhs bhs deleted the bhs/span_context_etc branch July 15, 2016 22:50
bhs added a commit that referenced this pull request Jul 24, 2016
Apparently IntelliJ decided to "intelligently" (sic) move some files to the wrong directories, resulting in some noise here.

This change re-introduces much of the type-enforcement lost during #32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants