Add explicit timestamp support for Span start/end.#571
Conversation
|
Also fixes #545 |
|
I think this is a good change. At some point in the future, it might be nice to not have the TimestampConverter us protobufs internally, but that can definitely wait. |
|
one hazard is allowing SDK be a dependency kitchen sink. I would recommend making strict dependency review a gate for any public release as it will cause problems for people who pull in OTel even if they dont use it. |
|
@adriancole thanks for the comment. The main idea is that only the API artifact will be used as dependency in third-party libraries, and we try hard to limit the dependencies there. |
bogdandrutu
left a comment
There was a problem hiding this comment.
Please split this PR into 2:
- Makes the API changes and with no implementation on the SDK (no-op); The API changes looks good in general.
- Changes the SDK. The timestamp logic does not seem correct to me and I would like to talk about that in more details;
| * @param endTimestamp the explicit end {@link Timestamp} for this {@code Span}. | ||
| * @since 0.1.0 | ||
| */ | ||
| void end(Timestamp endTimestamp); |
There was a problem hiding this comment.
To avoid breaking people in the future, should we go with an option pattern here? That will let us add more properties in the future without changing this.
Not 100% convinced but want to hear options.
There was a problem hiding this comment.
Sure, going with an option pattern sounds good to me. What about EndOptions, similar to what OC has? ;)
| Builder setSpanKind(Span.Kind spanKind); | ||
|
|
||
| /** | ||
| * Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
Null is not accepted from what I see, then we should explain to the users:
- when to set this.
- what to do when this is not needed.
There was a problem hiding this comment.
See your point. Will add extra clarification on this.
There was a problem hiding this comment.
I really want to discourage the following use patterns:
Timestamp now = Timestamp.fromMillis(System.currentMillis());
tracer.spanBuilder().setStartTime(now).startSpan();OR
tracer.spanBuilder().setStartTime(Timestamp.fromMillis(System.currentMillis())).startSpan();Can you please phrase this in a way to make sure we discourage the examples I gave to you?
There was a problem hiding this comment.
What is the reason for discouraging this usage?
There was a problem hiding this comment.
There are few reasons here:
- Java until java9 has only millis resolution (even java.time.Instant has only millis until java9).
- We do want to be able to calculate all the events (in all the spans in one trace) using nanoTime relative to only one TimeConvertor (which is read only for the first Span of this trace in this process) so we can guarantee ordering of events. When using an absolute timestamp like java Instant or system.currentTimeMillis these are not monotonic so events are not order correctly.
There was a problem hiding this comment.
Thanks! I suspected it was along these lines. Thanks for confirming.
There was a problem hiding this comment.
Probably same comment should be for all the methods that allow startTime.
There was a problem hiding this comment.
Yes (I know that we will also be adding explicit start time for Events)
|
cool I will raise another issue then as the hard dep on grpc-context in the
api package can easily leak implementation and/or pin deps
https://github.com/open-telemetry/opentelemetry-java/blob/50a2db42b257cb9618131bffc2fbc997785b7f38/api/src/main/java/io/opentelemetry/distributedcontext/package-info.java
probably to really be an api you should move grpc integration to another
jar as there are alternative and arguably better context integrations.
there shouldn't be a favorite that pins a dep to grpc in other words. i
will copy this text to the new issue
…On Sat, Sep 28, 2019, 10:15 PM Bogdan Drutu ***@***.***> wrote:
@adriancole <https://github.com/adriancole> thanks for the comment. The
main idea is that only the API artifact will be used as dependency in
third-party libraries, and we try hard to limit the dependencies there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#571?email_source=notifications&email_token=AAAPVV3VICGR7P2DLGL4XILQL5RIBA5CNFSM4I3BNMFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD722T7A#issuecomment-536193532>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAPVV3UC75GCS6D2NV2DL3QL5RIBANCNFSM4I3BNMFA>
.
|
8b2455d to
2278c23
Compare
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (64.28%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #571 +/- ##
=========================================
Coverage ? 78.19%
Complexity ? 686
=========================================
Files ? 83
Lines ? 2444
Branches ? 244
=========================================
Hits ? 1911
Misses ? 443
Partials ? 90 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3aa7af6 to
8148304
Compare
|
Hey @bogdandrutu I've updated the PR to not actually touch the SDK logic (as you suggested discussing the details for that in another PR). I've added a Things of interest:
Let me know ;) |
| Builder setSpanKind(Span.Kind spanKind); | ||
|
|
||
| /** | ||
| * Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
I really want to discourage the following use patterns:
Timestamp now = Timestamp.fromMillis(System.currentMillis());
tracer.spanBuilder().setStartTime(now).startSpan();OR
tracer.spanBuilder().setStartTime(Timestamp.fromMillis(System.currentMillis())).startSpan();Can you please phrase this in a way to make sure we discourage the examples I gave to you?
| * | ||
| * @since 0.1 | ||
| */ | ||
| public static EndSpanOptions getDefault() { |
There was a problem hiding this comment.
Not sure this is needed for the public API. Let's remove until someone asks for it.
| Builder setSpanKind(Span.Kind spanKind); | ||
|
|
||
| /** | ||
| * Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
Probably same comment should be for all the methods that allow startTime.
|
hey @bogdandrutu I've updated the code (making |
A few notes:
end(Timestamp)andsetStartTimestamp(Timestamp)will report an error in case the values arenull. This was done to keep uniformity with the rest of the API (although internally we are handling this case).TimestampConverteris created forSpans with explicit start time, and it's based on the aforementioned start time value.io.grpc.protobuf.Timestampinstances for the explicit values, if any.TimestampConverteralready requires one, anyway. Also, we get 'free' validation of the seconds/nanos.Fixes #24