# APM Java agent not passing data from the "service"

**URL:** <https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186>\
**Category:** APM\
**Created:** [October 19, 2018, 2:13pm UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186 "2018-10-19T14:13:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihai2018](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@mihai2018](https://discuss.elastic.co/u/mihai2018)\
**Post date:** [October 19, 2018, 2:13pm UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186/1 "2018-10-19T14:13:40Z")

</div>

Hello.

I've written several small Java TCs (DB test, HTTP test, etc), in plain Java (no framework below), everything seems fine, as far as configuration is concerned (APM confirms every item, including successful data transmission by the agent). However all I get in the server log is the following:

2018-10-19T16:45:19.797+0300 INFO [request] beater/handlers.go:282 handled request {"request\_id": "e733913f-46fb-44cb-bdc1-79403b4e7900", "method": "GET", "URL": "/healthcheck", "content\_length": 0, "remote\_address": "192.168.56.101", "user-agent": "co/elastic/apm/shaded/okhttp/3.9.1", "response\_code": 200}

And no data displaying in Kibana.  
Can you share a thought, especially regarding the "content\_length":0 thing ?

I've also activated DEBUG, below a sample output from one of the runs:  
2018-10-19 16:19:37.222 [main] INFO co.elastic.apm.configuration.StartupInfo - Starting Elastic APM 0.7.0 as getpost on Java 1.8.0\_141 (Oracle Corporation) Linux 4.1.12-112.14.2.el7uek.x86\_64  
2018-10-19 16:19:37.222 [main] DEBUG co.elastic.apm.configuration.StartupInfo - server\_urls: '[http://elk-node:8200](http://elk-node:8200)' (source: Java System Properties)  
2018-10-19 16:19:37.223 [main] DEBUG co.elastic.apm.configuration.StartupInfo - application\_packages: '-1' (source: Java System Properties)  
2018-10-19 16:19:37.223 [main] DEBUG co.elastic.apm.configuration.StartupInfo - log\_level: 'TRACE' (source: Java System Properties)  
...  
2018-10-19 16:19:37.274 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.ElasticApmApiInstrumentation$CaptureExceptionInstrumentation  
2018-10-19 16:19:37.274 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.TransactionInstrumentation$SetNameInstrumentation  
2018-10-19 16:19:37.275 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.TransactionInstrumentation$SetTypeInstrumentation  
2018-10-19 16:19:37.275 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.TransactionInstrumentation$AddTagInstrumentation  
2018-10-19 16:19:37.276 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.TransactionInstrumentation$SetUserInstrumentation  
...

- Applying advice co.elastic.apm.plugin.api.SpanInstrumentation$DoCreateSpanInstrumentation  
2018-10-19 16:19:37.280 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.SpanInstrumentation$EndInstrumentation  
2018-10-19 16:19:37.280 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.SpanInstrumentation$CaptureExceptionInstrumentation  
2018-10-19 16:19:37.280 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.SpanInstrumentation$GetIdInstrumentation  
2018-10-19 16:19:37.281 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.SpanInstrumentation$AddTagInstrumentation  
2018-10-19 16:19:37.281 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.plugin.api.CaptureExceptionInstrumentation  
2018-10-19 16:19:37.282 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.jdbc.ConnectionInstrumentation  
2018-10-19 16:19:37.282 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.jdbc.StatementInstrumentation  
...  
2018-10-19 16:19:37.286 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.opentracing.impl.ApmSpanInstrumentation$BaggageItemsInstrumentation  
2018-10-19 16:19:37.287 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.opentracing.impl.ApmSpanBuilderInstrumentation$CreateSpanInstrumentation  
...  
2018-10-19 16:19:37.298 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.servlet.AsyncInstrumentation  
2018-10-19 16:19:37.299 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.resttemplate.SpringRestTemplateInstrumentation  
2018-10-19 16:19:37.299 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applying advice co.elastic.apm.spring.webmvc.SpringTransactionNameInstrumentation  
2018-10-19 16:19:37.300 [main] DEBUG co.elastic.apm.bci.ElasticApmAgent - Applied 37 advices  
JSON String Result { "userId": 4, "id": 32, "title": "doloremque illum aliquid sunt", "body": "deserunt eos nobis asperiores et hic\nest debitis repellat molestiae optio\nnihil ratione ut eos beatae quibusdam distinctio maiores\nearum voluptates et aut adipisci ea maiores voluptas maxime"}  
{  
"userId": 101,  
"id": 101,  
"title": "Test Title",  
"body": "Test Body"  
}  
2018-10-19 16:19:38.218 [apm-reporter] TRACE co.elastic.apm.report.IntakeV1ReportingEventHandler - Receiving FLUSH event (sequence 0)  
2018-10-19 16:19:38.218 [apm-reporter] TRACE co.elastic.apm.report.IntakeV1ReportingEventHandler - Finished processing FLUSH event (sequence 0)  
POST Response Code : 201  
POST Response Message : Created  
{ "userId": 101, "id": 101, "title": "Test Title", "body": "Test Body"}

Thx really.  
Mihai

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [October 23, 2018, 10:41am UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186/2 "2018-10-23T10:41:43Z")

</div>

Hi Mihai,

Thanks a lot for trying out the Elastic APM Java agent.  
The log entry with `content_length:0` is not related to data sending, it is related to the healthcheck.  
Your DB queries and HTTP calls may be recorded by the agent as `Span`s, but in order for those to be sent, stored and viewed, they need to be part of `Transaction`s. The Java agent would create `Transaction`s out of the box when using [one of the supported frameworks](https://www.elastic.co/guide/en/apm/agent/java/current/supported-technologies-details.html#supported-web-frameworks), but since you are not relying on such, you would need to programatically create them, meaning [starting and ending them](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-start-transaction) from your code. Read through the documentation how to setup the dependency and using the API.

I hope you would find it easy to setup.  
Eyal.

---

<div class="post-metadata">

**Author:** ![mihai2018](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@mihai2018](https://discuss.elastic.co/u/mihai2018)\
**Post date:** [October 24, 2018, 1:44pm UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186/3 "2018-10-24T13:44:05Z")

</div>

Hi Eyal,

And thanks for the reply.

However I have 1 remark and 1 question:

Remark:

With all due respect for this interesting product, the documentation for "using the API" is really bad. And I really mean it.

Question:

I put together the different "hints" on your site and assembled the following simple code:

package apmfirst;

import co.elastic.apm.api.ElasticApm;  
import co.elastic.apm.api.Transaction;  
import co.elastic.apm.api.Span;

public class apmfirst {  
public static void main(String[] args) {

```
      Transaction transaction = ElasticApm.startTransaction();
      System.out.println("ID of current transaction: "+ transaction.getId());
      System.out.println("ID length of current transaction: "+ transaction.getId().length());

      try {
          transaction.setName("First transaction name");
          transaction.setType("First transaction test");
         
          // create some span
          Span span = transaction.createSpan();
          System.out.println("ID of current span: "+ span.getId());
          System.out.println("ID length of current span: "+ span.getId().length());

          try {
              span.setName("Second span's name");
              span.setType("Second span's type");
          } catch (Exception e) {
              span.captureException(e);
              throw e;
          } finally {
              span.end();
          }
         
      } catch (Exception e) {
          transaction.captureException(e);
          throw e;
      } finally {
          transaction.end();
      }
 }

```

}

Running it in my Eclipse IDE I get the output below:

_**ID of current transaction:  
ID length of current transaction: 0  
ID of current span:  
ID length of current span: 0**_

So, seemingly no transaction and no span are created (or at least they've got no IDs ...).

Can you please comment on these ?

PS. As a very minimum, to my mind, a very simple "Hello APM !", instrumented with a custom transaction/span, should have been on your site.

Thanks for your time,

Mihai

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [October 24, 2018, 2:57pm UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186/4 "2018-10-24T14:57:55Z")

</div>

Mihai,

Thanks for your input about the documentation, we will take your feedback into account.

Regarding your test code - seems to be correct, so maybe the documentation is not so bad after all 🙂. Did you also start this app with the agent itself? Because the jar you added to your code contains only the API, but the actual execution requires a full agent to be installed on the JVM.

So, just to clarify- as long as you are using supported technologies, the spans should be automatically captured by the agent, however, we cannot show them without relating them to a transaction, so what you will have to do is only the part of starting and ending transactions where it makes sense in your code.

I hope this helps.  
Eyal.

---

<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:** [November 14, 2018, 11:00am UTC](https://discuss.elastic.co/t/apm-java-agent-not-passing-data-from-the-service/153186/5 "2018-11-14T11:00:55Z")

</div>

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