# 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:** 20\
**Page:** 1

<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 14, 2018, 3:10pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/1 "2018-12-14T15:10:14Z")

</div>

Doing my best to create some custom code to use as a tracer and add into APM. It is the intention to create a transaction and append from different locations spans to it using context. Have started APM/Elastic/kibana stack on my local machine to debug. This does not result in anything. Would have hoped some failure or error, nothing is getting cought on APM/nor on Kibana or Elastic side.

My very simple code is below:

import java.util.concurrent.TimeUnit;

import co.elastic.apm.api.ElasticApm;  
import co.elastic.apm.api.Transaction;  
// import co.elastic.apm.impl.transaction.Span;  
import co.elastic.apm.api.Span;

public class TestAPM{  
public static void main(String args) {   
for(int i=0;i\<args.length;i++)  
System.out.println(args.length);  
String TransactionID = args[0];  
String SpanID = args[1];  
Transaction transaction = ElasticApm.startTransaction();  
try {  
transaction.setName("TransactionID");  
transaction.setType(Transaction.TYPE\_REQUEST);  
System.out.println(TransactionID);  
System.out.println(SpanID);  
// create the span under the transaction  
Span span = transaction.createSpan();  
try {  
span.setName("SpanID");  
span.setType("TBD");  
TimeUnit.SECONDS.sleep(5);  
System.out.println("\nwaiting for 5 seconds during the span");  
} catch (Exception e) {  
span.captureException(e);  
throw e;  
} finally {  
span.end();  
}  
} catch (Exception e) {  
transaction.captureException(e);  
try {  
throw e;  
} catch (Exception e1) {  
// TODO Auto-generated catch block  
e1.printStackTrace();  
}  
} finally {  
System.out.println("\nwaiting for 10 seconds to allow the creation");  
System.out.println("of a span in a different process");  
try {  
TimeUnit.SECONDS.sleep(10);  
} catch (InterruptedException e) {  
// TODO Auto-generated catch block  
e.printStackTrace();  
}  
transaction.end();  
}  
}  
}

Have also looked at all possible environment variables documented here: [https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html](https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html)

What is the best approach to debug ??

---

<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 14, 2018, 3:48pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/2 "2018-12-14T15:48:44Z")

</div>

Hi and thanks for trying out the Java agent.

Did you maybe forget to add the `-javaagent` flag?

--  
Felix

---

<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 17, 2018, 8:14am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/3 "2018-12-17T08:14:00Z")

</div>

Have tried all different combinations of environment variables. The code is about as simple as anything can be. If this does not work APM-agent does not work. Which other locations can you suggest for looking into potential issues. Would love something like a segmentation fault, or an entry in an error log, like this I am at a loss.

---

<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 17, 2018, 8:16am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/4 "2018-12-17T08:16:51Z")

</div>

I admit we have a possibility for an anti-virus kicking in. But where can I possibly identify this is indeed what is happening

---

<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 17, 2018, 8:32am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/5 "2018-12-17T08:32:27Z")

</div>

The thing is that even when you are using the API, you need to attach the javaagent. Otherwise nothing will happen the API does not include an implementation. The impel will be injected into the API only if the javaagent is added.

See here how to enable debug logging: [https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html](https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html)

---

<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 17, 2018, 1:02pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/6 "2018-12-17T13:02:30Z")

</div>

Have managed to define the javaagent as "VM arguments" inside eclipse. Don't understand what the other environment variables are for, mentioned in the documentation.  
Nevertheless I get a different error now:

2018-12-17 13:58:55.530 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as TestAPM on Java 1.8.0\_181 (Oracle Corporation) Windows 7 6.1  
Error: Could not find or load main class \

But at least I got an error.

---

<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 17, 2018, 1:27pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/7 "2018-12-17T13:27:41Z")

</div>

The good news is that it is probably configuration, as I can see this all the way in Kibana now:

error id icon

---

<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 17, 2018, 1:59pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/8 "2018-12-17T13:59:28Z")

</div>

Sounds like an Eclipse run configuration problem. Let me know if you need any further help.

---

<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 17, 2018, 3:26pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/9 "2018-12-17T15:26:35Z")

</div>

Don't think Eclipse is the problem.  
Now I make it through to the apm-agent call,  
but it fails to find the APM-server.  
It is running fine,  
in apm-server.yml:

# Defines the host and port the server is listening on. use "unix:/path/to.sock" to listen on a unix domain socket.

host: "localhost:8200"  
When in Cygwin I run this:  
netstat -na | grep 8200  
TCP 127.0.0.1:8200 0.0.0.0:0 LISTENING  
Which is what I expect.  
But still getting stuck:  
2018-12-17 16:25:47.297 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as TestAPM on Java 1.8.0\_181 (Oracle Corporation) Windows 7 6.1  
Error: Could not find or load main class \

---

<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 17, 2018, 3:39pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/10 "2018-12-17T15:39:23Z")

</div>

Have removed these settings on the Kibana side, one of the posts suggested that:  
#apm\_oss.errorIndices: apm-\*  
#apm\_oss.spanIndices: apm-\*  
#apm\_oss.transactionIndices: apm-\*  
#apm\_oss.onboardingIndices: apm-\*

Now Eclipse is back to  
2018-12-17 16:33:38.568 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as TestAPM on Java 1.8.0\_181 (Oracle Corporation) Windows 7 6.1  
Error: Could not find or load main class \

The Kibana side mentions in a repeatable way:  
December 17th 2018, 16:33:21.398  
listening:127.0.0.1:8200 @timestamp:December 17th 2018, 16:33:21.398 host.name:XXXYYYZZZ beat.hostname:XXXYYYZZZ beat.name:XXXYYYZZZ beat.version:6.5.1 processor.name:onboarding processor.event:onboarding \_id:MbzMvGcB2hbqiKRM4C3f \_type:doc \_index:apm-6.5.1-onboarding-2018.12.17 \_score: - view errors: - error id icon: -

Definately not Eclipse,  
Kibana and APM just don't work together,  
how can I fix that

---

<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 17, 2018, 4:15pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/11 "2018-12-17T16:15:54Z")

</div>

> [@jhoninck](#):
>
> Error: Could not find or load main class \

Seems like Java is trying to find a class named `\` which it obviously can't find. Could you post a screenshot of your Eclipse run configuration?

Thanks,  
Felix

---

<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 18, 2018, 8:30am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/12 "2018-12-18T08:30:42Z")

</div>

Which TAB on the Eclipse config are you looking for.  
In fact I managed to get the below JSON visible on the kibana side,  
but I still get the class not found error on eclipse:

{  
"\_index": "apm-6.5.1-onboarding-2018.12.18",  
"\_type": "doc",  
"\_id": "I39hwGcBz0kHYb-tITkq",  
"\_version": 1,  
"\_score": null,  
"\_source": {  
"listening": "127.0.0.1:8200",  
"@timestamp": "2018-12-18T08:14:09.082Z",  
"beat": {  
"hostname": "XXXYYYZZZ",  
"name": "XXXYYYZZZ",  
"version": "6.5.1"  
},  
"host": {  
"name": "XXXYYYZZZ"  
},  
"processor": {  
"name": "onboarding",  
"event": "onboarding"  
}  
},  
"fields": {  
"view errors": [  
null  
],  
"error id icon": [  
null  
],  
"@timestamp": [  
"2018-12-18T08:14:09.082Z"  
]  
},  
"sort": [  
1545120849082  
]  
}

---

<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 18, 2018, 8:48am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/13 "2018-12-18T08:48:07Z")

</div>

2018-12-18 09:42:56.206 [apm-server-healthcheck] WARN co.elastic.apm.report.ApmServerHealthChecker - Elastic APM server is not available (Unexpected end of file from server)  
2018-12-18 09:42:57.073 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as TestAPM on Java 1.8.0\_181 (Oracle Corporation) Windows 7 6.1  
Error: Could not find or load main class \

The first error "Elastic APM server is not available" is not true, it is listing on the correct port, towards which my program is sending data. Even the data is arriving at Kibana.

The VM arguments on eclipse are below:  
-javaagent:H:\elastic-apm-agent-1.1.0.jar   
-Delastic.apm.service\_name=TestAPM  
-Delastic.apm.server\_url=http://XXXYYYZZZ:8200  
-Delastic.apm.application\_packages=org.db  
-Delastic.apm.log\_level=INFO

---

<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 18, 2018, 8:51am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/14 "2018-12-18T08:51:59Z")

</div>

When I configure like this:  
-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.db  
-Delastic.apm.log\_level=INFO

Instead of hostname, I get a different error,  
but still the same final result

2018-12-18 09:48:43.562 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as TestAPM on Java 1.8.0\_181 (Oracle Corporation) Windows 7 6.1  
2018-12-18 09:48:43.641 [apm-server-healthcheck] INFO co.elastic.apm.report.ApmServerHealthChecker - Elastic APM server is available: {"ok":{"build\_date":"2018-11-16T01:21:45Z","build\_sha":"e9b22404feb418663d86f059b833bf1487d9379e","version":"6.5.1"}}  
Error: Could not find or load main class \

---

<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 18, 2018, 9:04am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/15 "2018-12-18T09:04:34Z")

</div>

If you remove the JVM arguments, do you still get this error?

> [@jhoninck](#):
>
> Error: Could not find or load main class \

Instead of `-javaagent:H:\elastic-apm-agent-1.1.0.jar`, could you try `-javaagent:H:/elastic-apm-agent-1.1.0.jar `?

---

<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 18, 2018, 10:01am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/16 "2018-12-18T10:01:02Z")

</div>

Hi felixbarny,  
I got everything working but, there is nothing showing in the APM services.

2018-12-18 15:18:46.335 [apm-server-healthcheck] DEBUG co.elastic.apm.report.ApmServerHealthChecker - Starting healthcheck to [http://127.0.0.1:8200/](http://127.0.0.1:8200/)  
2018-12-18 15:18:46.353 [apm-server-healthcheck] INFO co.elastic.apm.report.ApmServerHealthChecker - Elastic APM server is available: {"ok":{"build\_date":"2018-11-29T22:56:26Z","build\_sha":"ea0bf4863f638b35ecb6ced94f02015bab8bcb47","version":"6.5.2"}}  
2018-12-18 15:18:46.380 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 1.1.0 as standalonetest on Java 1.7.0\_80 (Oracle Corporation) Windows 8.1 6.3

Thanks.

---

<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 18, 2018, 10:26am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/17 "2018-12-18T10:26:11Z")

</div>

> [@jhoninck](#):
>
> -javaagent:H:\elastic-apm-agent-1.1.0.jar  
> -Delastic.apm.service\_name=TestAPM  
> -Delastic.apm.server\_url=[http://localhost:8200](http://localhost:8200)  
> -Delastic.apm.application\_packages=org.db  
> -Delastic.apm.log\_level=INFO

Eclipse showed a \ after the .jar  
when I removed it things started working more reliably

---

<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 18, 2018, 10:49am UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/18 "2018-12-18T10:49:17Z")

</div>

> [@Dark-Shadow-Side](#):
>
> I got everything working but, there is nothing showing in the APM services.

The UI only shows services which have sent transactions in the specified timeframe. Judging from your logs, the application has not sent any.

See the [troubleshooting guide](https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html) on how the logs are supposed to look like when transactions are sent.

---

<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 18, 2018, 5:02pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/19 "2018-12-18T17:02:34Z")

</div>

Thanks for your reply felixbarny, but will this work only with web projects in java?, I'm querying from DB but it still does not show up anything, but if used in a web project I can see the metrics. If there is a sample for standalone java project(not web based) it would be grateful. Thanks a lot

---

<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 18, 2018, 7:59pm UTC](https://discuss.elastic.co/t/debugging-information-for-java-agent/160925/20 "2018-12-18T19:59:08Z")

</div>

You can use our public api to manually create a transaction. The auto instrumentation will then add DB spans to the transaction.

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