# Debugging information for JAVA agent

**URL:** <https://discuss.elastic.co/t/debugging-information-for-java-agent/160925>\
**Category:** APM\
**Created:** [December 14, 2018, 3:10pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925 "2018-12-14T15:10:14Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Dark-Shadow-Side](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@Dark-Shadow-Side](https://discuss.elastic.co/u/Dark-Shadow-Side)\
**Post date:** [December 19, 2018, 7:41am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/21 "2018-12-19T07:41:38Z")

</div>

Hi felixbarny,  
below is my code but still I can't see the stats.  
public class TestAPM  
{

```
public static void main(String[] args)
{
    String TransactionID = args[0];
    String SpanID = args[1];
    Transaction transaction = ElasticApm.startTransaction();
    try
    {
        transaction.setName("TransactionID");
        transaction.setType(Transaction.TYPE_REQUEST);
        
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/billing", "devuser", "devuser");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("Select uname,esmeaddr from custdb.Users LIMIT 5");
        while (rs.next())
        {
            System.out.println(rs.getString("uname") + rs.getString("esmeaddr"));
            TimeUnit.SECONDS.sleep(5);
        }
    }
    catch (Exception e)
    {
        transaction.captureException(e);
        try
        {
            throw e;
        }
        catch (Exception e1)
        {
            e1.printStackTrace();
        }
    }
    finally
    {
        try
        {
            TimeUnit.SECONDS.sleep(10);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
        transaction.end();
    }
}

```

}

LOG:  
2018-12-19T13:07:34.896+0530 INFO [request] beater/common\_handlers.go:272 handled request {"request\_id": "ac290c88-f3ca-459c-b3d6-a3ddd198ec85", "method": "GET", "URL": "/", "content\_length": 0, "remote\_address": "127.0.0.1", "user-agent": "Java/1.8.0\_171", "response\_code": 200}  
2018-12-19T13:08:11.295+0530 INFO [request] beater/v2\_handler.go:111 error handling request {"request\_id": "3428ca85-9528-4862-b6f2-f0d299596292", "method": "POST", "URL": "/intake/v2/events", "content\_length": -1, "remote\_address": "127.0.0.1", "user-agent": "java-agent/1.1.0", "error": "read tcp 127.0.0.1:8200-\>127.0.0.1:54510: wsarecv: An existing connection was forcibly closed by the remote host."}

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [December 19, 2018, 7:50am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/22 "2018-12-19T07:50:27Z")

</div>

> [@Dark-Shadow-Side](#):
>
> "error": "read tcp 127.0.0.1:8200-\>127.0.0.1:54510: wsarecv: An existing connection was forcibly closed by the remote host."

That's interesting. There seems to be a problem with the connection from the agent to the server. Are there any proxies or firewalls in between you may need to adjust? Could you post the logs from the agent?

---

<div class="post-metadata">

**Author:** ![Dark-Shadow-Side](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@Dark-Shadow-Side](https://discuss.elastic.co/u/Dark-Shadow-Side)\
**Post date:** [December 19, 2018, 9:16am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/23 "2018-12-19T09:16:37Z")

</div>

Sure,  
[https://pastebin.com/63MDQGcd](https://pastebin.com/63MDQGcd)

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [December 19, 2018, 9:50am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/24 "2018-12-19T09:50:17Z")

</div>

Ah, I think I know what the problem is. Your program terminates before the agent sends the data from the background thread to the server!

What you can do is to wait 20 seconds before terminating the program. You can also adjust the flush interval with this setting: [https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-flush-interval](https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-flush-interval).

I'll submit a patch so that it flushes the data on exit.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [December 21, 2018, 1:01pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/25 "2018-12-21T13:01:09Z")

</div>

Have you had success when waiting for the events to be sent?

I have created a PR to flush the events on application shutdown: [https://github.com/elastic/apm-agent-java/pull/397](https://github.com/elastic/apm-agent-java/pull/397)

---

<div class="post-metadata">

**Author:** ![jhoninck](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jhoninck](https://discuss.elastic.co/u/jhoninck)\
**Post date:** [December 21, 2018, 1:45pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/26 "2018-12-21T13:45:46Z")

</div>

Yes it was succesfull,

On holiday right now,

Will pick it up after the first of Jan

---

<div class="post-metadata">

**Author:** ![jhoninck](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jhoninck](https://discuss.elastic.co/u/jhoninck)\
**Post date:** [January 3, 2019, 10:32am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/27 "2019-01-03T10:32:04Z")

</div>

Have managed to get things running on localhost, getting quite some information back. The configuration of the  
run-VM arguments of eclipse  
resolved it.  
A bit confusing as it is also referenced inside my pom.xml file.

-javaagent:H:\elastic-apm-agent-1.1.0.jar  
-Delastic.apm.service\_name=TestAPM  
-Delastic.apm.server\_url=http://localhost:8200  
-Delastic.apm.application\_packages=org.xx  
-Delastic.apm.log\_level=INFO

Some other issues on the horizon now,  
different topic though.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 24, 2019, 6:32am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/28 "2019-01-24T06:32:10Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

[Previous page](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925.md?page=1)
