-
Notifications
You must be signed in to change notification settings - Fork 20
Failing streaming endpoints do return trace IDs #45
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
| import javax.ws.rs.container.ContainerRequestContext; | ||
| import javax.ws.rs.core.MediaType; | ||
| import javax.ws.rs.core.Response; | ||
| import javax.ws.rs.core.StreamingOutput; | ||
| import javax.ws.rs.core.UriInfo; | ||
| import org.glassfish.jersey.client.JerseyClientBuilder; | ||
| import org.junit.After; | ||
|
|
@@ -156,6 +157,36 @@ public void testTraceState_withoutRequestHeadersGeneratesValidTraceResponseHeade | |
| assertThat(spanCaptor.getValue().getOperation(), is("GET /trace")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTraceState_withoutRequestHeadersGeneratesValidTraceResponseHeadersWhenFailing() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that this test succeeded before this fix |
||
| Response response = target.path("/failing-trace").request().get(); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.TRACE_ID), not(nullValue())); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. taking a step back, it's not clear to me that the response needs to contain a trace id header at all (even in the success case).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the general case of streaming one? I'm confused, this is how it's been working so far everywhere. If not provided on the request headers, a trace will be created and returned so that you can find out what happens. This makes even more sense IMHO when things go wrong. For what it's worth, here even forcing the trace with request headers is ignored in the failing streaming case. Doesn't really matter if you force it or let it pick, the exception handling breaks it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, that sounds reasonable. |
||
| assertThat(response.getHeaderString(TraceHttpHeaders.PARENT_SPAN_ID), is(nullValue())); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.SPAN_ID), is(nullValue())); | ||
| verify(observer).consume(spanCaptor.capture()); | ||
| assertThat(spanCaptor.getValue().getOperation(), is("GET /failing-trace")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTraceState_withoutRequestHeadersGeneratesValidTraceResponseHeadersWhenStreaming() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that this test succeeded before this fix |
||
| Response response = target.path("/streaming-trace").request().get(); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.TRACE_ID), not(nullValue())); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.PARENT_SPAN_ID), is(nullValue())); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.SPAN_ID), is(nullValue())); | ||
| verify(observer).consume(spanCaptor.capture()); | ||
| assertThat(spanCaptor.getValue().getOperation(), is("GET /streaming-trace")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTraceState_withoutRequestHeadersGeneratesValidTraceResponseHeadersWhenFailingToStream() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test fails before this fix, and succeeds with this fix |
||
| Response response = target.path("/failing-streaming-trace").request().get(); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.TRACE_ID), not(nullValue())); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.PARENT_SPAN_ID), is(nullValue())); | ||
| assertThat(response.getHeaderString(TraceHttpHeaders.SPAN_ID), is(nullValue())); | ||
| verify(observer).consume(spanCaptor.capture()); | ||
| assertThat(spanCaptor.getValue().getOperation(), is("GET /failing-streaming-trace")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTraceState_withSamplingHeaderWithoutTraceIdDoesNotUseTraceSampler() { | ||
| target.path("/trace").request() | ||
|
|
@@ -216,13 +247,33 @@ public final void run(Configuration config, final Environment env) throws Except | |
|
|
||
| public static final class TracingTestResource implements TracingTestService { | ||
| @Override | ||
| public void getTraceOperation() {} | ||
| public void getTraceOperation() { | ||
| throw new RuntimeException("FAIL"); | ||
| } | ||
|
|
||
| @Override | ||
| public void postTraceOperation() {} | ||
|
|
||
| @Override | ||
| public void getTraceWithPathParam() {} | ||
|
|
||
| @Override | ||
| public void getFailingTraceOperation() { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| @Override | ||
| public StreamingOutput getFailingStreamingTraceOperation() { | ||
| return os -> { | ||
| throw new RuntimeException(); | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public StreamingOutput getStreamingTraceOperation() { | ||
| return os -> { | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| @Path("/") | ||
|
|
@@ -240,5 +291,19 @@ public interface TracingTestService { | |
| @GET | ||
| @Path("/trace/{param}") | ||
| void getTraceWithPathParam(); | ||
|
|
||
| @GET | ||
| @Path("/failing-trace") | ||
| void getFailingTraceOperation(); | ||
|
|
||
| @GET | ||
| @Path("/failing-streaming-trace") | ||
| @Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
| StreamingOutput getFailingStreamingTraceOperation(); | ||
|
|
||
| @GET | ||
| @Path("/streaming-trace") | ||
| @Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
| StreamingOutput getStreamingTraceOperation(); | ||
| } | ||
| } | ||
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's pretty funky that this filter is called twice in the case of a failing streaming response... indicates to me that we don't fully understand the jersey behavior here.
ignoring our ignorance for a moment, the fix seems ok to me, but i'd like to see a comment indicating why this
elseblock exists and what it does and how.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.
Agreed, will do