-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add tracing for entity reading and writing. #46
Add tracing for entity reading and writing. #46
Conversation
cebdfa4
to
ea0e6d9
Compare
@hypnoce hi, thanks for a nice contribution! I have a couple of general comments:
|
No problem, I will make the needed changes when I'm out of meetings :) |
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.
It looks good. We need to change reference types to be semantically correct.
@@ -39,7 +39,7 @@ public void testDefaultOperationNameAndTags() { | |||
.get(); | |||
response.close(); | |||
|
|||
Assert.assertEquals(1, mockTracer.finishedSpans().size()); | |||
Assert.assertEquals(2, mockTracer.finishedSpans().size()); |
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.
Could you please also test the second span?
} | ||
|
||
private void assertSerializationSpan(MockSpan parentSpan, MockSpan serializationSpan) { | ||
Assert.assertTrue(Objects.toString(serializationSpan.tags().get("media.type")).contains(MediaType.TEXT_PLAIN)); |
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.
Assert.equals
is better here. The same for server tests.
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.
Resteasy client returns the charset. Will make sure to remove it before assertion.
@Path("/postWithBody") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public Response postWithBody(@Context HttpServletRequest request, String body) throws ExecutionException, InterruptedException { |
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 we can have only this endpoint and remove putWithBody
and get
|
||
@Test | ||
public void testSerializationResponseAndRequestWithBody() { | ||
String response = client.target(url("/postWithBody")) |
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.
Could you please use ClientBuilder.newClient()
here? There is already a test for testing if wiring works properly.
List<MockSpan> mockSpans = mockTracer.finishedSpans(); | ||
Assert.assertEquals(2, mockSpans.size()); | ||
|
||
final MockSpan serializationSpan = mockSpans.get(1); |
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.
Client requests
- Serialization of request body happens between the tracing filter invocation so we can use
child_of
. - Deserialization happens after the request is processed by the client filter therefore we cannot use
child_of
relationship. We should change this tofollows_from
see https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans
Server requests
- Deserialization happens between the span in the server filter is started and finished so we can use
child_of
- Serialization of response entity happens after the server span if finished so we can use only
follows_from
. (a note for me: If we integrate with servlet filter Integrate with servlet filter #13 then the wrapping span would be always finished after writing the entity).
For more see: https://jersey.github.io/documentation/latest/user-guide.html#d0e9613
If we are going to unify interceptors then we have to do:
- use the same name for span wrappers
- check if span wrapper has been finished or not when starting a serialization/deserialization span
@@ -27,7 +30,7 @@ public void testServerStandardTags() throws Exception { | |||
.get(); | |||
response.close(); | |||
|
|||
Assert.assertEquals(1, mockTracer.finishedSpans().size()); | |||
Assert.assertEquals(2, mockTracer.finishedSpans().size()); |
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.
Could you please remove server entities from /clientTracingChaining
and "/hello/{id}
so the tests remain as they are?
00f96d1
to
2cd62a2
Compare
@pavolloffay I made the changes according to your helpful comments. Let me know if there is anything else. |
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.
Look good just a couple of comments.
import io.opentracing.BaseSpan; | ||
import javax.ws.rs.ext.InterceptorContext; | ||
|
||
public interface SerdeInterceptorSpanDecorator { |
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 there is a typo Serde
import javax.ws.rs.ext.WriterInterceptor; | ||
import javax.ws.rs.ext.WriterInterceptorContext; | ||
|
||
public abstract class SerdeTracingInterceptor implements WriterInterceptor, ReaderInterceptor { |
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.
a typo Serde
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.
Name just TracingInterceptor
would work.
if(spanWrapper == null) { | ||
return NoopActiveSpanSource.NoopActiveSpan.INSTANCE; | ||
} | ||
final Tracer.SpanBuilder serdeSpanBuilder = tracer.buildSpan(operationName); |
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.
typo serde?
/** | ||
* Set static serialization operation names. | ||
*/ | ||
SerdeInterceptorSpanDecorator SERIALIZE_OPERATION_NAME = new SerdeInterceptorSpanDecorator() { |
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.
We don't need this decorator, it uses the same operation names as hardcoded ones.
* Use the current HttpServletRequest to lookup the current span wrapper. | ||
*/ | ||
@Context | ||
private HttpServletRequest servletReq; |
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.
:) we see more differences between impls
try { | ||
return context.proceed(); | ||
} catch (Exception e) { | ||
Tags.ERROR.set(activeSpan, true); |
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.
Could you please add a todo here
// Add exception logs in case they are not added by the filter.
@pavolloffay I used 'serde' as a convention when dealing with serialisation and deserialisation classes. I saw this in kafka I think :). Removed. |
2cd62a2
to
acbd6a3
Compare
@pavolloffay I just noticed something : the follows_from reference is never used. Indeed, in case of a synchronous request, the spanWrapper object is never finished. Therefore, when checking for completion in TracingInterceptor, the spanWrapper is not finished but the actual underlying span is. Also, in the mock tracing library, there is no simple way to check for follows_from reference type as it is added as a normal parent. |
I will have a look at this PR today.
agree mock tracer does not support it, either multiple references. I will create an issue in upstream. |
MockTracer issue opentracing/opentracing-java#210. @hypnoce you are right Line 103 in c443ad9
I will do a fix PR and then retest this. |
@pavolloffay I made a fix on my side. But hard to test unless I had a filter to get the spanWrapper and check if it's finished. |
The fix is here #47 |
acbd6a3
to
8e700ef
Compare
Rebased. I still cannot test for follows_from. Do you want to wait until we can properly validate this ? |
I think it will take a longer time to get it implemented in OT API. We can create an issue to fix 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.
Just a minor comments, It looks great!
@@ -10,6 +10,8 @@ | |||
*/ | |||
public class SpanWrapper { | |||
|
|||
public static final String SPAN_PROP_ID = SpanWrapper.class.getName() + ".activeSpanWrapper"; |
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.
We can change it to PROPERTY_NAME
.
@@ -78,13 +81,15 @@ public void testAsyncSever() throws Exception { | |||
response.close(); | |||
|
|||
List<MockSpan> mockSpans = mockTracer.finishedSpans(); | |||
Assert.assertEquals(2, mockSpans.size()); | |||
Assert.assertEquals(3, mockSpans.size()); |
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.
Could you please change /async
endpoint to not return any value so the interceptor does not kick in.
8e700ef
to
38efd07
Compare
@pavolloffay made changes according to your last comments. Added a PR for exposing reference type from MockSpan : opentracing/opentracing-java#213 |
@hypnoce thanks. I will merge and create an issue to test it. |
Hi all,
I added reader and writer interceptors to measure serialization time.
The code of the client and server are almost the same. I can factorise them if needs be.
Let me know if you have any comment on the feature itself and on the implementation. I will be happy to hear them.
Thanks