# Elastic java APM agent connect to sample java application which have only db calls without any server connections

**URL:** <https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850>\
**Category:** APM\
**Tags:** java\
**Created:** [April 7, 2020, 8:08am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850 "2020-04-07T08:08:51Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 8:08am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/1 "2020-04-07T08:08:51Z")

</div>

Hi all,  
I need to collect data from java apm agent to apm server.  
My jar is simple java application which has only internal db calls dont have any rest or serer and it is not a web application.

I need to monitor those db queries please help me with this.

**Kibana version** :7.2.1

**Elasticsearch version** :7.2.1

**APM Server version** :7.2.1

**APM Agent language and version** :1.14.0 java

**Browser version** :

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**:download page

\*\*Fresh install or upgraded from other version?\*\*fresh install

**Is there anything special in your setup?** For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

**Steps to reproduce** :  
1.  
2.  
3.

**Errors in browser console (if relevant)**:

**Provide logs and/or server output (if relevant)**:

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [April 7, 2020, 8:34am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/2 "2020-04-07T08:34:54Z")

</div>

Hi @renu_jessi,

What is the nature of your application ? does it have a GUI or any command-line interface ?

Agent has two main concepts to represent what is being executed within the application:

- transaction: enclosing scope of what is observed, mostly entry point to the application like "processing an http request for a web-application".
- spans: unit of work, which is often delegated to another service, like a database query, calling another web-service, ...

Having only an "internal" database would not make much difference, but for example if you have an application with a GUI our agent won't provide out-of-the-box support for common GUI frameworks like Swing or AWT, and you'll have to use agent API to define transactions.

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 8:43am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/3 "2020-04-07T08:43:51Z")

</div>

it dont have any gui i have one main class whish has db connection details and executing one query.i have export this project as jar and attached to elastic apm.no data is captured fron elastic agent am getting

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [April 7, 2020, 8:53am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/4 "2020-04-07T08:53:14Z")

</div>

Ok, then you should be able to create transactions using agent API: [https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html)

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 6:44pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/5 "2020-04-07T18:44:45Z")

</div>

Hi,

my application is not spring boot i dont have pom. xml how can i use this

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [April 7, 2020, 6:50pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/6 "2020-04-07T18:50:18Z")

</div>

You can download it from [maven](https://search.maven.org/search?q=g:co.elastic.apm%20AND%20a:apm-agent-api) and use it in your application.

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 6:51pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/7 "2020-04-07T18:51:35Z")

</div>

i had already tried..i had downloades that elastic apm agent jar file and added it in my build path still import statements are getting error

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 6:53pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/8 "2020-04-07T18:53:34Z")

</div>

whixh jar i need to add.. i have actually added elastic-apm-agent.1.14.0.jar

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [April 7, 2020, 6:55pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/9 "2020-04-07T18:55:15Z")

</div>

apm-agent-api.version.jar

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 7, 2020, 6:59pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/10 "2020-04-07T18:59:00Z")

</div>

i tried this still getting error

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [April 7, 2020, 7:50pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/11 "2020-04-07T19:50:12Z")

</div>

[Here](https://github.com/kananindzya/apm-command-line-public-api-example) I added simple example and readme for it.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [April 8, 2020, 7:13am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/12 "2020-04-08T07:13:35Z")

</div>

Also, you have to make sure that `elastic-apm-agent` jar is not in your application dependencies, you should only add to the command line when starting the application using `-javaagent` argument.

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 8, 2020, 12:10pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/13 "2020-04-08T12:10:37Z")

</div>

HI,

I am getting below error after compiling from command line.but when i run from my eclipse it is working fine and getting result also.

ERROR:

javac -cp ./lib/apm-agent-api-0.6.1.jar:. -sourcepath src src/sample\_apm/com/MessengerMain.java

By giving second command :

command:

java -javaagent:D:\<user\>\APM\elastic-apm-agent-.jar -Delastic.apm.service\_name=NAME -Delastic.apm.server\_url=http://localhost:8200 -Delastic.apm.application\_packages=com -cp lib/apm-agent-api-0.6.1.jar:src/ com.Main

ERROR:  
2020-04-08 17:38:54.761 [main] INFO co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state  
Error: Could not find or load main class sample\_apm.com.MessengerMain  
2020-04-08 17:38:57.109 [elastic-apm-init-instrumentation-shutdown-hook] INFO co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to STOPPED state

---

<div class="post-metadata">

**Author:** ![renu\_jessi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/renu_jessi/32/55702_2.png) [@renu\_jessi](https://discuss.elastic.co/u/renu_jessi)\
**Post date:** [April 8, 2020, 12:20pm UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/14 "2020-04-08T12:20:42Z")

</div>

command:

java -javaagent:D:\1210353\APM\elastic-apm-agent-1.14.0.jar -Delastic.apm.service\_name=ECI\_Sample -Delastic.apm.server\_url=http://localhost:8200 -Delastic.apm.application\_packages=sample\_apm.com -cp D:\1210353\APM\Project\_jars\sample\_apm.jar lib/apm-agent-api-0.6.1.jar:src/ sample\_apm.com.MessengerMain

ERROR:

java.lang.IllegalStateException: Cannot locate field named span for class co.elastic.apm.api.TransactionImpl

Along with this my db call executed successfull.but agent status is still not success.

please help me with this

---

<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:** [April 29, 2020, 8:20am UTC](https://discuss.elastic.co/t/elastic-java-apm-agent-connect-to-sample-java-application-which-have-only-db-calls-without-any-server-connections/226850/15 "2020-04-29T08:20:53Z")

</div>

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