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

DISCUSSION: Add SpanWatcherProcessor (spec#373) #697

Closed

Conversation

Oberon00
Copy link
Member

@Oberon00 Oberon00 commented Dec 13, 2019

This is an example implementation of open-telemetry/opentelemetry-specification#373. It depends on #693 to detect ended spans.

The SpanWatcherProcessor is 80% a copy of the BatchSpansProcessor. It uses a list of weak references to detect Spans that were dropped by the user without ending them, as to not cause memory leaks.

It is probably rather slow since it has to use toSpanData on every span. To detect whether it was ended already, an alternative would be to use the onEnd callback, but then the spans would have to be stored in a map structure and some locking would have to take place there. Having an isEnded property on ReadableSpan would be more efficient. The age of the span (getStartEpochNanos) can also only be calculated with the SpanData. Assuming that most spans in applications have a duration of less than the reportInterval of the SpanWatcherProcessor, having just one of hasEnded or getStartEpochNanos exposed on the ReadableSpan should already bring a good improvement.

@Oberon00 Oberon00 changed the title Add SpanWatcherProcessor (open-telemetry/opentelemetry-specification#373) DISCUSSSION: Add SpanWatcherProcessor (open-telemetry/opentelemetry-specification#373) Dec 13, 2019
@Oberon00 Oberon00 changed the title DISCUSSSION: Add SpanWatcherProcessor (open-telemetry/opentelemetry-specification#373) DISCUSSSION: Add SpanWatcherProcessor (spec#373) Dec 13, 2019
@Oberon00 Oberon00 changed the title DISCUSSSION: Add SpanWatcherProcessor (spec#373) DISCUSSION: Add SpanWatcherProcessor (spec#373) Dec 13, 2019
@codecov-io
Copy link

codecov-io commented Dec 13, 2019

Codecov Report

Merging #697 into master will increase coverage by 0.52%.
The diff coverage is 89.42%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #697      +/-   ##
============================================
+ Coverage     78.21%   78.74%   +0.52%     
- Complexity      761      769       +8     
============================================
  Files            98       99       +1     
  Lines          2676     2780     +104     
  Branches        247      257      +10     
============================================
+ Hits           2093     2189      +96     
- Misses          484      490       +6     
- Partials         99      101       +2
Impacted Files Coverage Δ Complexity Δ
...lemetry/sdk/trace/export/SpanWatcherProcessor.java 89.42% <89.42%> (ø) 7 <7> (?)
...elemetry/sdk/trace/export/BatchSpansProcessor.java 89.36% <0%> (+1.06%) 7% <0%> (ø) ⬇️
...elemetry/opentracingshim/SpanContextShimTable.java 96.42% <0%> (+7.14%) 8% <0%> (+1%) ⬆️

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 1e3a5ca...11e35ab. Read the comment docs.

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.

Some high-level comments.

*
* @return the end nano time.
*/
private long getEndEpochNanos() {
synchronized (lock) {
return getEndNanoTimeInternal();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to keep the behavior to expose the duration for active (for example in OpenCensus z-pages we want to show for how long the Span was active), we have two options:

  • Add a hasEnded on the SpanData and keep the end-time to be Clock::now
  • Expose the Clock instance in SpanData.

I tend to like more the first option.

Copy link
Member Author

@Oberon00 Oberon00 Dec 13, 2019

Choose a reason for hiding this comment

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

That comment would be better at #74 EDIT: #693 😃

Actually I'd like to have the hasEnded on the ReadableSpan already.

* <p>This batch {@link SpanProcessor} can cause high contention in a very high traffic service.
* TODO: Add a link to the SpanProcessor that uses Disruptor as alternative with low contention.
*/
public final class SpanWatcherProcessor implements SpanProcessor {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is very similar to https://github.com/open-telemetry/opentelemetry-java/blob/master/sdk/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpansProcessor.java. Is it possible to share at least the Worker/Queuing logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as stated in the description, it is probably 80% the same. But the span watcher has no queue, it has a watchlist. Spans are not removed on export. I'm not sure how easily one could share code. Also the types are slightly different since the watcher has to convert to SpanData earlier.

Copy link
Member Author

Choose a reason for hiding this comment

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

As of recently, the conversion to SpanData is now at the same point as in the BatchSpansProcessor, so the types have become even more similar now.

Copy link
Member

Choose a reason for hiding this comment

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

So if I understand correctly you will try to avoid duplicated code, is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey sorry for not replying, I will leave this PR lying around some more while we are still discussing requirements for this span processor (e.g. if it should also optionally export ended spans).

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
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
@bogdandrutu
Copy link
Member

bogdandrutu commented Feb 20, 2020

@Oberon00 is this PR still needed? If you still need time to think we can put a holding_on label, or close and reopen when ready.

@Oberon00
Copy link
Member Author

Hi, I think the PR has become obsolete in the meantime.

@Oberon00 Oberon00 closed this Feb 20, 2020
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.

4 participants