-
Notifications
You must be signed in to change notification settings - Fork 845
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
[On Hold] Improve behavior of un-ended ReadableSpan #693
[On Hold] Improve behavior of un-ended ReadableSpan #693
Conversation
79b9fe0
to
4582da8
Compare
Codecov Report
@@ Coverage Diff @@
## master #693 +/- ##
============================================
- Coverage 78.42% 78.38% -0.05%
Complexity 746 746
============================================
Files 93 93
Lines 2609 2618 +9
Branches 234 239 +5
============================================
+ Hits 2046 2052 +6
- Misses 466 467 +1
- Partials 97 99 +2
Continue to review full report at Codecov.
|
sdk/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java
Show resolved
Hide resolved
I'm not sure we need the latency on the span data, but I'll add it in a separate commit for now. |
Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697
Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697
The only reason to have now() returned in getEndEpochNanos seems to be that it kinda makes sense for getLatencyMs, but that method is package-private and never used. See also open-telemetry/opentelemetry-specification#373 (comment).
65f0592
to
9875df5
Compare
sdk/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java
Outdated
Show resolved
Hide resolved
@arminru You probably want to re-review that, since a lot has changed since your approval. |
Actually, when adding the latency to |
sdk/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java
Outdated
Show resolved
Hide resolved
This reverts commit b3e419a.
a1fc2b6
to
b7114f0
Compare
b7114f0
to
a030e1b
Compare
@open-telemetry/java-approvers Anyone care to look at this? Do you think I should really add the latency to SpanData? |
boolean hasEnded(); | ||
|
||
/** | ||
* Returns the latency of the {@code Span} in nanos. If still active then returns now() - start |
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 think it would be nice in this javadoc to define "latency" in this context, because it is a word that some may interpret as meaning "network latency", which seems like an odd thing to have on a generic 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.
Actually I think it might be better to just rename this to currentDuration
. Latency, while technically correct (see open-telemetry/opentelemetry-specification#330), is probably confusing to most users.
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.
Or maybe "elapsedTime" ?
@@ -190,6 +192,13 @@ public SpanData toSpanData() { | |||
return result; | |||
} | |||
|
|||
@Override | |||
public boolean hasEnded() { | |||
synchronized (lock) { |
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.
this proliferation of synchronization really makes me want to implement this with AtomicBoolean, since it's lock-free.
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.
You could remove the lock here then, but all the checks for hasEnded
within span still need to hold the lock if they want to ensure that they don't set properties after the span has ended.
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.
yeah. IMO, the whole thread-safety of this class is pretty janky. We should think about separating the mutable parts from the immutable and having a simpler synchronization model.
* @return {@code true} if the span has already been ended, {@code false} if not. | ||
* @since 0.4.0 | ||
*/ | ||
public abstract boolean getHasEnded(); |
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 recommend just "hasEnded" without the extraneous get
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.
Unfortunately, AutoValue seems to require a get
-prefix here (see also getHasRemoteParent
).
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.
yet another reason for me to hate autovalue
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'm trying to decide if isEnded
is better, or just as ugly
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.
isFinished
?
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 think isFinished
sounds like it would be true if the span is exported (finished passing through the span pipeline). Maybe a name for the inverse could be used, like isRunning
.
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 like that idea!
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.
isActive
? just to throw out another option
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.
Being "active" (on a scope) is already another concept in OpenTelemetry, unfortunately.
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 like isRunning
if (!getLatencyNanos().isPresent() | ||
&& getStartEpochNanos().isPresent() | ||
&& getEndEpochNanos().isPresent() | ||
&& getEndEpochNanos().get() >= getStartEpochNanos().get()) { |
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.
this is really ugly block of code. Can we at least move it into it's own method?
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.
Actually, this is only required for tests. The best option from my perspective would be to remove the latency from SpanData.
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 am fine with removing latency from the SpanData. For the EndEpoch what is the behavior you want?
@Oberon00 I think this PR got very hard to review, and I cannot follow all the changes, can you please consider to: split PR if possible in changes to ReadableSpan and changes to SpanData, update the description of the PR and documented what changed. |
I split #733 from this one, will do further splitting once that one is handled. |
* Add hasBeenEnded property to ReadableSpan. * Add hasBeenEnded to SpanData. * Rename hasBeenEnded to hasEnded. In-reply-to: #693 (comment) * Check SpanData.hasEnded in unit test. * Fix mismerge.
Please rebase to include the latest merged PR. |
Closing this one in favor of #737. |
Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697
Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697
Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697
* feat: introduce ended property on Span Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697 * chore: adapt after merge from master * chore: revert changes in API * chore: remove unneeded isEnded
* feat: introduce ended property on Span Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697 * chore: adapt after merge from master * chore: revert changes in API * chore: remove unneeded isEnded
* feat: introduce ended property on Span Add a getter to Span and ReadableSpan to allow checking if the span is ended without using a private field or rely on internals like span.duration[0] < 0. Refs: open-telemetry/opentelemetry-java#693 Refs: open-telemetry/opentelemetry-java#697 * chore: adapt after merge from master * chore: revert changes in API * chore: remove unneeded isEnded
Original title: Simplify span end time.
The only reason to have now() returned in getEndEpochNanos seems to be
that it kinda makes sense for getLatencyMs, but that method is
package-private and never used.
See also
open-telemetry/opentelemetry-specification#373 (comment).