Kibana version :
7.10.2
Elasticsearch version :
7.10.2
APM Server version :
1.17.0
APM Agent language and version :
Java
Browser version :
Chrome 79.0.3945.117
Original install method (e.g. download page, yum, deb, from source, etc.) and version :
download page and local setup
Fresh install or upgraded from other version?
No
**
Hello!
In our application we use code provided by third party company that handle SOAP calls.
This class AsyncResponse
use HttpURLConnection
to communicate. Problem is that when user click on GUI, SOAP call is creating in separated thread. Agent catch user click and create GUI transaction, but on this transaction there is no span that should be created by HttpUrlConnectionInstrumentation
. When SOAP call is creating in same thread that GUI all work fine. I get span created by HttpUrlConnectionInstrumentation.
Class is big and I can not provide code so I will show some pseudo code to better understand
public class AsyncResponse {
private AsyncResponse<T, E>.WebserviceThread _thread = new AsyncResponse.WebserviceThread();
private class WebserviceThread extends Thread {
WebserviceInvocationThread() {
super("WSI-Invocation");
}
public void run() {
// connect HttpURLConnection
// inputStream
// outputStream
// here should create Span from HttpUrlConnectionInstrumentation
}
public void waitForCallComplete(long timeout) {
// check timeout and throw TimeoutException
}
}
public void getResponse() {
this._thread.start();
this.waitForCallComplete(90000);
}
}
Seem to when creating new child thread all APM context is loosing.
In test package I see code that test HttpUrlConnectionInstrumentation
in differen thread.
public void testEndInDifferentThread() throws Exception {
final HttpURLConnection urlConnection = new HttpURLConnectionWrapper(new HttpURLConnectionWrapper((HttpURLConnection) new URL(getBaseUrl() + "/").openConnection()));
urlConnection.connect();
final Thread thread = new Thread(tracer.getActive().withActive(() -> {
try {
urlConnection.getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}));
thread.start();
thread.join();
verifyHttpSpan("/");
}
Problem Is that I can not change code where different thread is created.
Any idea how to solve this issue ?
Thank you for help