-
Notifications
You must be signed in to change notification settings - Fork 345
Problems around the new io.opentracing.tag.Tag api #340
Comments
added a pull request for the major features needed. a little more work to do. pausing a bit notably you can see the hack here https://github.com/openzipkin-contrib/brave-opentracing/pull/93/files#r271152691 |
@tylerbenson correct me if I am wrong, but it looks like your original intention (#311) with this method <T> Span setTag(AbstractTag<T> key, T value); was NOT to require that implementations call However, later on in 9b6ca36 it was changed to <T> Span setTag(Tag<T> tag, T value); I think we need to fix this by documenting that indeed the implementations of these span/builder methods are expected to do a double-dispatch by delegating to the passed public <T> Tracer.SpanBuilder withTag(Tag<T> tag, T value) {
this.initialTags.put(tag.getKey(), value);
return this;
} Alternatively, we could remove/deprecate these two methods from span/builder, as they seem to be causing more issues than they are worth. |
Hey hey
Going through the history of this change, I can also see that we ended up with an actual different thing. My feeling is that we should document the expected behavior (the double dispatch part) should be enough for this API (as we won't have many upcoming releases). |
For double-dispatch to work on SpanBuilder the Tag interface needs an extra method |
@yurishkuro I guess I don't fully understand the problem you're referring to with the double-dispatch and how it relates to SpanBuilder. Is your issue with the need for double dispatch? |
Sorry, double dispatch is probably a jargon used for Visitor-like pattern, which is very similar to Tag: span.Set(tag,v) => tag.Set(span,v) => span Set(tag.key, v) The same doesn't work for span builder today because the middle part is missing from Tag interface: tag.Set(spBldr, v) |
@yurishkuro on @Override
public <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
return withTag(tag.getKey(), value);
} I realize this isn't as nice as with I must be missing something... Where does this break down? |
It won't compile 😄 withTag methods are strongly typed, but here we don't know the type of the value. Double dispatch through concrete tag works because it makes the value type concrete. |
@yurishkuro I see my problem now... we had a private method in our implementation that each of the
Which is why I didn't discover this problem when doing integration testing. |
@tylerbenson exactly, the same happened in MockTracer in the original PR, we could've caught it there. |
While I can't quite trace the background for it,
io.opentracing.tag.Tag
appears to have been added last week. There are a number of problems around it, which I'll catalog here:tag.set(span, value)
is 3 characters less than directly callingspan.setTag(tag, value)
. It would be nice to know why this should have broken api.On problems with adding
withTag(Tag<T> tag, T value)
to SpanBuilder, especially in context to the sampling flag.OT has no sampling api (still) and we are supposed to interpret
Tags.SAMPLING_PRIORITY
as a sampling hint. This means we need to know the value duringSpanBuilder
hydration.However, the signature of
io.opentracing.tag.Tag
isSpan
, notSpanBuilder
. This api gap causes problems.One way is to make a dummy span implementation that catches the result of Tag.set so that we can inspect the value as if it were made with SpanBuilder directly. For example, if the key matches sampling, we use a special dummy span to record the result of Tag.set similar to how mock libraries work. Then, we can get the value of sampling before we create a span.
Other options are to remove the
withTag(Tag<T> tag, T value)
signature from the builder, or addset(SpanBuilder builder, T value);
to Tag.The text was updated successfully, but these errors were encountered: