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

[On Hold] Improve behavior of un-ended ReadableSpan #693

Conversation

Oberon00
Copy link
Member

@Oberon00 Oberon00 commented Dec 12, 2019

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

@Oberon00 Oberon00 force-pushed the simplify-span-endtime branch from 79b9fe0 to 4582da8 Compare December 12, 2019 12:01
@codecov-io
Copy link

codecov-io commented Dec 12, 2019

Codecov Report

Merging #693 into master will decrease coverage by 0.04%.
The diff coverage is 85%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...ntelemetry/sdk/trace/RecordEventsReadableSpan.java 89.65% <100%> (+0.18%) 49 <1> (ø) ⬇️
...main/java/io/opentelemetry/sdk/trace/SpanData.java 89.28% <40%> (-10.72%) 2 <0> (ø)
...telemetry/contrib/metrics/runtime/MemoryPools.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...etry/contrib/metrics/runtime/GarbageCollector.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...elemetry/sdk/trace/export/BatchSpansProcessor.java 89.36% <0%> (+1.06%) 7% <0%> (ø) ⬇️

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 7505c12...a030e1b. Read the comment docs.

@Oberon00 Oberon00 changed the title Simplify span end time. Simplify span end time (changes semantics of end time of active span) Dec 12, 2019
@Oberon00 Oberon00 changed the title Simplify span end time (changes semantics of end time of active span) Improve behavior of un-ended ReadableSpan Dec 16, 2019
@Oberon00
Copy link
Member Author

I'm not sure we need the latency on the span data, but I'll add it in a separate commit for now.

Flarna added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 16, 2019
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
Flarna added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 16, 2019
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
@Oberon00 Oberon00 force-pushed the simplify-span-endtime branch from 65f0592 to 9875df5 Compare December 16, 2019 12:29
@Oberon00 Oberon00 requested a review from arminru December 16, 2019 12:34
@Oberon00
Copy link
Member Author

@arminru You probably want to re-review that, since a lot has changed since your approval.

@Oberon00
Copy link
Member Author

Oberon00 commented Dec 16, 2019

Actually, when adding the latency to SpanData it breaks all the tests in #697 because now the latency is among the values that are compared when comparing SpanData objects, and calling toSpanData on an un-ended span will have a different value there every time. That's fixable but cumbersome. I wonder if we really want to have the latency at the SpanData or if the ReadableSpan is enough.

@Oberon00 Oberon00 force-pushed the simplify-span-endtime branch from a1fc2b6 to b7114f0 Compare December 17, 2019 10:34
@Oberon00 Oberon00 force-pushed the simplify-span-endtime branch from b7114f0 to a030e1b Compare December 17, 2019 10:40
@Oberon00
Copy link
Member Author

@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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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

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.

Copy link
Member Author

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.

Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFinished ?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea!

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

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?

Copy link
Member Author

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.

Copy link
Member

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?

@bogdandrutu
Copy link
Member

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

Oberon00 added a commit to dynatrace-oss-contrib/opentelemetry-java that referenced this pull request Jan 7, 2020
Oberon00 added a commit to dynatrace-oss-contrib/opentelemetry-java that referenced this pull request Jan 7, 2020
@Oberon00 Oberon00 changed the title Improve behavior of un-ended ReadableSpan [On Hold] Improve behavior of un-ended ReadableSpan Jan 7, 2020
@Oberon00
Copy link
Member Author

Oberon00 commented Jan 7, 2020

I split #733 from this one, will do further splitting once that one is handled.

bogdandrutu pushed a commit that referenced this pull request Jan 7, 2020
* 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.
@bogdandrutu
Copy link
Member

Please rebase to include the latest merged PR.

@Oberon00
Copy link
Member Author

Oberon00 commented Jan 8, 2020

Closing this one in favor of #737.

@Oberon00 Oberon00 closed this Jan 8, 2020
Flarna added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Feb 4, 2020
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
Flarna added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Feb 4, 2020
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
Flarna added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Feb 4, 2020
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
dyladan pushed a commit to open-telemetry/opentelemetry-js that referenced this pull request Mar 10, 2020
* 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
SuperButterfly pushed a commit to SuperButterfly/opentelemetry-js that referenced this pull request Sep 18, 2022
* 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
viridius-1 pushed a commit to viridius-1/opentelemetry-js that referenced this pull request Jan 14, 2023
* 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
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.

6 participants