-
Notifications
You must be signed in to change notification settings - Fork 848
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
Prototype for JFR events using Context interceptor #963
Conversation
looks like we need to make sure this doesn't try to be built by CI when building with java 8. |
As you can see in SpanProcessor I need to keep a state, currently just a basic ConcurrentHashMap. The risk is that this will cause extra overhead and risk when a lot of spans a flowing through as it needs to be thread safe. I think there are two possible ideas for how to handle this without requiring for the processor to keep an internal state.
|
contrib/jfr_events/src/main/java/io/grpc/override/AbstractSimpleContextStorageListener.java
Outdated
Show resolved
Hide resolved
contrib/jfr_events/src/main/java/io/opentelemetry/contrib/jfr/JfrContextStorageListener.java
Outdated
Show resolved
Hide resolved
contrib/jfr_events/src/main/java/io/opentelemetry/contrib/jfr/JfrContextStorageListener.java
Outdated
Show resolved
Hide resolved
contrib/jfr_events/src/main/java/io/opentelemetry/contrib/jfr/JfrContextStorageListenerNew.java
Outdated
Show resolved
Hide resolved
contrib/jfr_events/src/main/java/io/opentelemetry/contrib/jfr/JfrSpanProcessor.java
Outdated
Show resolved
Hide resolved
@Description( | ||
"Open Telemetry trace event corresponding to the span currently " | ||
+ "in scope/active on this thread.") | ||
class ScopeEvent extends Event { |
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.
should this be public? With the JFR streaming APIs is this going to be handed directly to the stream listeners?
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.
Haven't done much with the JFR stream, but doubt you will get the actual event class and rather get a generic event type that you can look up name and fields on?
This is very cool, @sfriberg . Is your intent to move this out of "prototype" status and get it spruced up for official inclusion as a contrib module? |
Thanks for the review @jkwatson. I think the main blockers is how we want to do the GRPC context integration. The other one would be if we should change the Processor API so it would be possible to avoid keeping a state here to capture when a Span is closed. (See my comment above about ideas). The second part I don't see as a blocker and we can improve as we go, but I think we need to understand how we will handle GRPC before this is merged. |
settings.gradle
Outdated
@@ -42,6 +42,10 @@ include ":opentelemetry-all", | |||
":opentelemetry-sdk-contrib-jaeger-remote-sampler", | |||
":opentelemetry-bom" | |||
|
|||
if(JavaVersion.current().isJava11Compatible()) { |
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.
Have you considered testing against any Java 8 distributions that include JFR?
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 have not, once that becomes readily available we can look at building for JDK 8 as well. First step I think is to focus on JDK 11 and make that work well.
|
Codecov Report
@@ Coverage Diff @@
## master #963 +/- ##
=============================================
+ Coverage 0 85.35% +85.35%
- Complexity 0 2117 +2117
=============================================
Files 0 241 +241
Lines 0 8086 +8086
Branches 0 893 +893
=============================================
+ Hits 0 6902 +6902
- Misses 0 853 +853
- Partials 0 331 +331
Continue to review full report at Codecov.
|
...s/jfr_events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrContextStorageProvider.java
Outdated
Show resolved
Hide resolved
For some reason this fails and even crashes the JVM when running the test. It seems like this is due to the build setup of the project as things are working if lift this out as a single separate Gradle project instead. @anuraaga I believe you did some of the changes with the build process lately, anything you have a clue about what might be causing it? |
Signed-off-by: Staffan Friberg <[email protected]>
Span capturing is still less efficient than desirable, but works. The following issue to track it, #1105. Jacoco has been disabled due to a bug in the JDK, which breaks the code coverage I believe. Despite that I think this should be possible to merge 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.
Thanks @sfriberg - this seems like a cool implementation :)
import io.opentelemetry.context.ContextStorage; | ||
import io.opentelemetry.context.Scope; | ||
|
||
public class JfrContextStorageWrapper implements ContextStorage { |
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.
Does this class need to be public?
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, since it needs to be possible to register for any user.
ContextStorage.addWrapper(JfrContextStorageWrapper::new);
ScopeEvent event = new ScopeEvent(Span.fromContext(toAttach).getSpanContext()); | ||
event.begin(); | ||
return () -> { | ||
event.commit(); |
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.
What happens if the event is never committed? Is there a way to detect it in JFR? Then it looks like it could be a nice scope debugging mechanism.
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.
No way to detect, it basically is just GC:ed never to be seen or heard from again :).
...extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java
Outdated
Show resolved
Hide resolved
*/ | ||
public class JfrSpanProcessor implements SpanProcessor { | ||
|
||
private final Map<SpanContext, SpanEvent> spanEvents = new ConcurrentHashMap<>(); |
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.
Should we use weak keys for this? It's bad for tracing if a bug means spans are never ended and leaked, but this would cause an actual memory leak I think.
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.
By the way I've been thinking of shading in https://github.com/raphw/weak-lock-free/blob/master/src/main/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMap.java for our use for a different Context-related use case, if that'll help I can prioritize it :)
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.
Good catch. By using Guava there should be no need to shade another class
...extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
spanEvents.forEach((id, event) -> event.commit()); |
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.
Hmm - not really for this PR but this doesn't seem like how shutdown is supposed to work. For example, we would probably stop accepting spans, and wait for spans to end naturally in an exporter when it is shutting down I think. But can't think of any improvement here so just writing for reference.
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.
Probably would be good to improve the JavaDoc, not sure what 'not yet processed means'.
- Processes all span events that have not yet been processed and closes used resources.
Similar for forceFlush
- Processes all span events that have not yet been processed.
Sound more like this would be for finished spans rather than span that hasn't been closed yet.
Force flush would commit any ready events, as would shutdown but that would also clear up all resources, which I would take as drop all non-completed spans. Once something is shutdown I wouldn't expect things to continue to flow, unless the CompleteResultCode would wait for all spans, but that would potentially be indefinite.
will remove the event.commit part as that feels wrong here
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.
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.
what does "pending requests" mean here? Un-ended spans? Or just spans that were in the process of being sent off to exporters?
sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/ScopeEvent.java
Outdated
Show resolved
Hide resolved
...nsions/jfr-events/src/test/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessorTest.java
Outdated
Show resolved
Hide resolved
@anuraaga Thanks for the review. I believe I have fixed all your comments. |
…xtension/jfr/JfrSpanProcessor.java Co-authored-by: Anuraag Agrawal <[email protected]>
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.
Thanks! Just small comment 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.
Cool!
No description provided.