-
Notifications
You must be signed in to change notification settings - Fork 848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit timestamp support for Span start/end. #571
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, going with an option pattern sounds good to me. What about EndOptions
, similar to what OC has? ;)
@@ -421,6 +433,15 @@ | |||
*/ | |||
Builder setSpanKind(Span.Kind spanKind); | |||
|
|||
/** | |||
* Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See your point. Will add extra clarification on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for discouraging this usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I suspected it was along these lines. Thanks for confirming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably same comment should be for all the methods that allow startTime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes (I know that we will also be adding explicit start time for Event
s)
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
@@ Coverage Diff @@
## master #571 +/- ##
============================================
- Coverage 78.27% 78.19% -0.09%
+ Complexity 706 686 -20
============================================
Files 85 83 -2
Lines 2546 2444 -102
Branches 250 244 -6
============================================
- Hits 1993 1911 -82
+ Misses 461 443 -18
+ Partials 92 90 -2
Continue to review full report at Codecov.
|
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 ;) |
@@ -421,6 +433,15 @@ | |||
*/ | |||
Builder setSpanKind(Span.Kind spanKind); | |||
|
|||
/** | |||
* Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is needed for the public API. Let's remove until someone asks for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me.
@@ -421,6 +433,15 @@ | |||
*/ | |||
Builder setSpanKind(Span.Kind spanKind); | |||
|
|||
/** | |||
* Sets an explicit start {@link Timestamp} for the newly created {@code Span}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).TimestampConverter
is created forSpan
s with explicit start time, and it's based on the aforementioned start time value.io.grpc.protobuf.Timestamp
instances for the explicit values, if any.TimestampConverter
already requires one, anyway. Also, we get 'free' validation of the seconds/nanos.Fixes #24