Skip to content
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

Merged
merged 6 commits into from
Oct 11, 2019

Conversation

carlosalberto
Copy link
Contributor

A few notes:

  • Both end(Timestamp) and setStartTimestamp(Timestamp) will report an error in case the values are null. This was done to keep uniformity with the rest of the API (although internally we are handling this case).
  • A new TimestampConverter is created for Spans with explicit start time, and it's based on the aforementioned start time value.
  • Internally (SDK) I'm creating/passing around 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.
    • HOWEVER, I'm not doing start/end timestamps comparison nor validation.

Fixes #24

@carlosalberto
Copy link
Contributor Author

Also fixes #545

@jkwatson
Copy link
Contributor

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.

@codefromthecrypt
Copy link
Contributor

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.

@bogdandrutu
Copy link
Member

@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.

Copy link
Member

@bogdandrutu bogdandrutu left a 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:

  1. Makes the API changes and with no implementation on the SDK (no-op); The API changes looks good in general.
  2. 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);
Copy link
Member

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.

Copy link
Contributor Author

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}.
Copy link
Member

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:

  1. when to set this.
  2. what to do when this is not needed.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor

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?

Copy link
Member

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:

  1. Java until java9 has only millis resolution (even java.time.Instant has only millis until java9).
  2. 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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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 Events)

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Sep 29, 2019 via email

@codecov-io
Copy link

codecov-io commented Sep 30, 2019

Codecov Report

Merging #571 into master will decrease coverage by 0.08%.
The diff coverage is 64.28%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
api/src/main/java/io/opentelemetry/trace/Span.java 100% <ø> (ø) 0 <0> (ø) ⬇️
...ava/io/opentelemetry/sdk/trace/SpanBuilderSdk.java 93.06% <0%> (-1.89%) 32 <0> (ø)
...ntelemetry/sdk/trace/RecordEventsReadableSpan.java 96.71% <0%> (-1.21%) 48 <0> (-10)
...ain/java/io/opentelemetry/trace/DefaultTracer.java 75% <100%> (+1.31%) 6 <0> (ø) ⬇️
.../main/java/io/opentelemetry/trace/DefaultSpan.java 70.73% <100%> (+1.5%) 14 <1> (+1) ⬆️
...in/java/io/opentelemetry/trace/EndSpanOptions.java 100% <100%> (ø) 4 <4> (?)
...butedcontext/DefaultDistributedContextManager.java 36.36% <0%> (-24.25%) 6% <0%> (-1%)
.../io/opentelemetry/opentracingshim/Propagation.java 60% <0%> (-14.2%) 3% <0%> (-1%)
.../java/io/opentelemetry/sdk/internal/TestClock.java 90.9% <0%> (-9.1%) 6% <0%> (-1%)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ac8d2d...e864973. Read the comment docs.

@carlosalberto
Copy link
Contributor Author

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 EndSpanOptions class (similar to what OC has) to contain an optional, nullable end Timestamp.

Things of interest:

  1. Timestamp is an actual class. At first I had it as an interface, so vendors could extend it, but it feels like an overkill for such a small container.
  2. Felt like adding a convenience create(Timestamp endTimestamp) method, so users don't have to create a builder when only setting this value, but didn't include it for cleanliness reasons.

Let me know ;)

@@ -421,6 +433,15 @@
*/
Builder setSpanKind(Span.Kind spanKind);

/**
* Sets an explicit start {@link Timestamp} for the newly created {@code Span}.
Copy link
Member

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() {
Copy link
Member

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.

Copy link
Contributor Author

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}.
Copy link
Member

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.

@carlosalberto
Copy link
Contributor Author

hey @bogdandrutu I've updated the code (making EndSpanOptions.getDefault() private). Let me know if this is good for you to merge (as discussed in the Java SIG last Friday).

@bogdandrutu bogdandrutu merged commit 0612372 into open-telemetry:master Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow explicit start/end timestamp for Span
6 participants