-
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
DISCUSSION: Add SpanWatcherProcessor (spec#373) #697
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
Some high-level comments.
* | ||
* @return the end nano time. | ||
*/ | ||
private long getEndEpochNanos() { | ||
synchronized (lock) { | ||
return getEndNanoTimeInternal(); |
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.
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.
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.
* <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 { |
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 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?
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, 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.
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.
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.
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.
So if I understand correctly you will try to avoid duplicated code, is that correct?
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.
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).
sdk/src/main/java/io/opentelemetry/sdk/trace/export/SpanWatcherProcessor.java
Outdated
Show resolved
Hide resolved
sdk/src/main/java/io/opentelemetry/sdk/trace/export/SpanWatcherProcessor.java
Outdated
Show resolved
Hide resolved
sdk/src/main/java/io/opentelemetry/sdk/trace/export/SpanWatcherProcessor.java
Outdated
Show resolved
Hide resolved
sdk/src/main/java/io/opentelemetry/sdk/trace/export/SpanWatcherProcessor.java
Show resolved
Hide resolved
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
6ff8d6e
to
cb55c40
Compare
This requires the more robust test, otherwise everything becomes very flaky.
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
@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. |
Hi, I think the PR has become obsolete in the meantime. |
* 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
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 theonEnd
callback, but then the spans would have to be stored in a map structure and some locking would have to take place there. Having anisEnded
property onReadableSpan
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.