-
Notifications
You must be signed in to change notification settings - Fork 332
Keep spans active during AsyncHandler methods in AsyncHttpClient #1172
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 5 commits
c2cd89e
355f20c
8463d41
b2eb4e5
09b0479
2e577d0
3d08881
766688b
a8fa295
4cf8353
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 |
|---|---|---|
|
|
@@ -11,9 +11,9 @@ | |
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
|
|
@@ -25,10 +25,7 @@ | |
| package co.elastic.apm.agent.asynchttpclient; | ||
|
|
||
| import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; | ||
| import org.asynchttpclient.AsyncCompletionHandlerBase; | ||
| import org.asynchttpclient.AsyncHttpClient; | ||
| import org.asynchttpclient.Dsl; | ||
| import org.asynchttpclient.RequestBuilder; | ||
| import org.asynchttpclient.*; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.runner.RunWith; | ||
|
|
@@ -38,6 +35,7 @@ | |
| import java.util.Arrays; | ||
|
|
||
| import static org.asynchttpclient.Dsl.asyncHttpClient; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class AsyncHttpClientInstrumentationTest extends AbstractHttpClientInstrumentationTest { | ||
|
|
@@ -49,11 +47,35 @@ public AsyncHttpClientInstrumentationTest(RequestExecutor requestExecutor) { | |
| this.requestExecutor = requestExecutor; | ||
| } | ||
|
|
||
| public static AsyncHandler<Response> customAsyncHandler = new AsyncCompletionHandler<Response>() { | ||
| @Override | ||
| public State onStatusReceived(HttpResponseStatus responseStatus) { | ||
| assertThat(tracer.currentTransaction()).isNotNull(); | ||
| assertThat(tracer.currentTransaction().isExit()).isTrue(); | ||
| return State.CONTINUE; | ||
| } | ||
|
|
||
| @Override | ||
| public void onThrowable(Throwable t) { | ||
| assertThat(tracer.currentTransaction()).isNotNull(); | ||
| assertThat(tracer.currentTransaction().isExit()).isTrue(); | ||
| } | ||
|
|
||
| @Override | ||
| public Response onCompleted(Response response) { | ||
| assertThat(tracer.currentTransaction()).isNotNull(); | ||
|
Member
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. To double-check, do the tests fail when doing
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. Ill double-check all PR requirements now and make sure the tests make sense :)
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. Mmm, the changes make the existing tests fail (even when I remove the newly added Seems to me that is a local problem linked to my laptop. Will try to figure out why it is doing that. Any chance you have a docker-image able to run the tests?
Member
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. The tests are failing on CI for the same reason. Not sure what causes that 🤔
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. Oh wow, interesting. Very strange that the new instrumentations make the current tests time-out. Will have a look later today when I have a bit more time :)
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. I tried to figure it out but tbh, I have no idea.
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. @felixbarny I've played around with it a bit more: This prints out: So it seems that activating the span does not mean I can do
Member
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. Yes, that's true. You should assert that
Member
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. See also #1174
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. Cool, thanks :) |
||
| assertThat(tracer.currentTransaction().isExit()).isTrue(); | ||
| return response; | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| @Parameterized.Parameters() | ||
| public static Iterable<RequestExecutor> data() { | ||
| return Arrays.asList( | ||
| (client, path) -> client.executeRequest(new RequestBuilder().setUrl(path).build()).get(), | ||
| (client, path) -> client.executeRequest(new RequestBuilder().setUrl(path).build(), new AsyncCompletionHandlerBase()).get(), | ||
| (client, path) -> client.executeRequest(new RequestBuilder().setUrl(path).build(), customAsyncHandler).get(), | ||
| (client, path) -> client.prepareGet(path).execute(new AsyncCompletionHandlerBase()).get(), | ||
| (client, path) -> client.prepareGet(path).execute().get() | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.