openzipkin / zipkin-ruby

zipkin-tracer ruby gem
Apache License 2.0
99 stars 38 forks source link

Don't report span.timestamp or duration when you didn't create the span #91

Open codefromthecrypt opened 7 years ago

codefromthecrypt commented 7 years ago

Zipkin's RPC span is interesting because it is a shared model. For example, a client creates a span and then the next hop (a server) adds annotations to it. The authoritative owner of the span is the one that's supposed to set timestamp and duration. In the case where it is originated by a client, the client, not the server, should set timestamp and duration.

See https://github.com/openzipkin/openzipkin.github.io/issues/49

Why bother?

If we special-case timestamp and duration reporting, a couple things happen:

Do we need to do anything?

I'm not sure if the current implementation is doing this fine or not, but it is probably useful to add tests to make sure it it. Usually, there's very little to do to special-case this, and it always is where B3 headers are read.

Here are tests that should smoke it out

Does this make sense? Can anyone help translate this into tests for us?

See https://github.com/openzipkin/brave/issues/277#issuecomment-262429392

codefromthecrypt commented 7 years ago

ps mostly unrelated, but in some other implementations, when we start a span, we log a tick (or otherwise start a timer). When this is set (ex it wouldn't be set if it were a continued server span), we extract a measurement in microseconds as duration. Using this is more reliable than system time, as it never risks moving backwards during a span (ex from NTP adjustments). Not sure best mechanism in ruby, but I've found http://ruby-doc.org/stdlib-2.3.3/libdoc/benchmark/rdoc/Benchmark.html and https://github.com/copiousfreetime/hitimes

jcarres-mdsol commented 7 years ago

I think the third one would not pass and require several changes. The first two it are easy, you got the ids , someone else is owning this, else you own this. The third is weird, "the lack of this optional sampled header in fact means you own this", weird. Current code will not like this

codefromthecrypt commented 7 years ago

The third is weird, "tha lack of this optional sampled header in fact means you own this", weird. Current code will not like this

well, if you think about it, it makes sense. You'd never propagate sampled=1 unless you started the span. lack of a sampled header means "defer sampling decision downstream" which means it hasn't been sampled or reported yet. anyway, we can leave out part 3 for now, just it will eventually come up. when it does, this is how it would be handled.

codefromthecrypt commented 7 years ago

in other words the sampled header is indeed required for any span that the caller reports to zipkin. I can fix the b3 docs as it seems unclear.

codefromthecrypt commented 7 years ago

actually it is already there.. https://github.com/openzipkin/b3-propagation#details