How can I instrument APM agent with a core JAVA service?

I have successfully instrumented JAVA APM agent with my web application that runs on Tomcat but I am not sure on how to instrument it with my core java service (that does not run on any server)?

Any suggestions would help!

Take a look at the public API...

This tells you how to create your own transactions and spans.

Then depending on the communication protocols you'll probably have to figure out how to pass the parents transaction IDs if you through some form of headers or the message itself or use opentracing bridge if you want to see distributed tracing.

Here is a sample the TCP example to demonstrate.

1 Like

So does it mean that if we use elastic-apm-agent.jar then we can only get hold of default transactions?

If you just use the agent without the Public API you will automatically get transactions for the supported frameworks.

If your app does not use one of the supported frameworks you would use the agent plus the Public API.

That example I gave uses the agent + the Public API since it was just raw tcp i.e. not a supported framework.

Thanks Stephen. It does make sense now. But what do you think would be a preferred way of using APM agent then, would it be using Public API or programmatic API setup to self attach?

Especially when you have to provide a generalized solution across all different Java micro-services [micro-services with different Java framework implementation] running on your platform?

Well It Depends ...

It depends on many things how your code is organized, how it is built your CI CD pipelines, the different Java frameworks and messaging systems involved. I would certainly take advantage of any of the automatic instrumentation for the frameworks that are supported. I don't think there's a simple answer to this and it's going to take some discussion, thought and it'll be a bit of a journey for sure.

I think I would approach it in an iterative manner take a look at some candidate and/or your most important services, or the set of services that are most common with the largest footprint (depends on your goals) and instrument them first and prepare that you will evolve / iterate how you do it.

That said the very first one I would do would be a small Canary project meaning a very small service with low-impact for the first one I'd roll into production to make sure you understand impact and how to configure in production.

If there are a bunch of different development groups it'll be difficult to push that on all of them. What I have found works in the past is get something working well and then other developers will want to take advantage of that.

If I sound like an engineering manager its because I was for many years .... good luck on your journey.

Keep coming back and asking questions and let us know how it's going.

Thanks a lot Stephen, this definitely helps.

One more help Stephen, When I am trying to instrument Elastic Java Agent to an appplication which uses spring boot [with Tomcat], I am getting the following error:

2019-07-23 22:10:07.893 [apm-reporter] ERROR - Failed to handle event of type METRICS with this error: apm-server-service
2019-07-23 22:10:07.893 [apm-reporter] INFO - Backing off for 1 seconds (+/-10%)
2019-07-23 22:10:37.757 [apm-reporter] ERROR - Failed to handle event of type METRICS with this error: apm-server-service
2019-07-23 22:10:37.757 [apm-reporter] INFO - Backing off for 4 seconds (+/-10%)
2019-07-23 22:11:07.773 [apm-reporter] ERROR - Failed to handle event of type METRICS with this error: apm-server-service
2019-07-23 22:11:07.773 [apm-reporter] INFO - Backing off for 9 seconds (+/-10%)
2019-07-23 22:11:37.758 [apm-reporter] ERROR - Failed to handle event of type METRICS with this error: apm-server-service
2019-07-23 22:11:37.758 [apm-reporter] INFO - Backing off for 16 seconds (+/-10%)

I am not sure If I did something wrong: Following is the configurational detail on how I achieved this:

Used -javaagent along with other -Delastic parameters in order to deploy the application. Also added with the same system properties under /bin on the container while opening permission to execute by doing chmod +x /bin/

Looking forward to get more insight on this.


Can you get the simple petclinc work in tomcat?

the reason I asked if you looked at this thread at the very end they finally figure it out they weren't using a supported framework. Are you using some other framework with your spring boot?

Thanks a lot Stephen, I think it was my bad while configuring Kubernetes External Name Service [DNS]. Figured out & resolved the issue.

1 Like

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