Elastic-apm-agent.jar on PCF

How to add elastic-apm-agent.jar on PCF environment ?

1 Like

Hi and sorry for the late answer. You can try out an upcoming experimental installation method: https://www.elastic.co/guide/en/apm/agent/java/master/setup-attach-api.html. You'll have to use version 1.3.1-SNAPSHOT add add the sonatype snapshot repository:

    <repositories>
       <repository>
         <id>snapshots-repo</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
         <releases><enabled>false</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
       </repository>
     </repositories>

I'm not sure it it actually works on pivotal cloud foundry but it's worth a try :slight_smile:

I hope that helps.

Cheers,
Felix

Hi,

Thanks for using the Java Agent and deploying on PCF.

You can insert the java APM agent into your deployable jar and then configure in the manifest.

Here is an example using the spring-petclinic project.

git clone https://github.com/spring-projects/spring-petclinic.git

cd spring-petclinic/

./mvnw package -Dmaven.test.skip=true

Now this is a little brute force but demonstrates the principle. You insert the elastic-apm-agent-1.3.0.jar into the app deployable jar.

curl -O  https://search.maven.org/remotecontent?filepath=co/elastic/apm/elastic-apm-agent/1.3.0/elastic-apm-agent-1.3.0.jar

jar -uf target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar elastic-apm-agent-1.3.0.jar

Check to make sure the agent made it into the jar

jar -tvf target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar | grep apm

Create a manifest file spring-petclinic-monolith-manifest-apm.yml.

The apm-server server must be resolvable outside Cloud Foundry or use an IP address. In this case I also turned on the trace_methods capability, this will show all the methods in the petclinic package. This can create some overhead but I am just showing so you can see the level of detail if needed.

---
applications:
- name: spring-petclinic-monolith
  memory: 1G
  path: ./target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar
  env:
    JAVA_OPTS: -javaagent:./elastic-apm-agent-1.3.0.jar -Delastic.apm.server_urls=https://apm.yourapmserver.net:8200 -Delastic.apm.service_name="spring-petclinic-monolith" -Delastic.apm.application_packages="org.springframework.samples" -Delastic.apm.trace_methods="org.springframework.samples.petclinic.*#*"

Then deploy the app

cf push spring-petclinic-monolith -f spring-petclinic-monolith-manifest-apm.yml

Now navigate to the application and click around and you should see the transaction begin to show up in in the APM Dashboard / App. Make sure your time frame is set etc.

Cheers,
Stephen

1 Like

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