Even APM agent can add parameter -javaAgent, but it will more flexible if embed in jar file. This demo will show how to add ELK APM agent inside Java gradle project.
Prerequisites
- Ensure network connectivity between source and destination.
Steps
- Add ELK stack APM agent.
In build.gradle, add dependencies as below.dependencies { implementation 'co.elastic.apm:apm-agent-attach:1.+' }
- Externalize APM agent configuration.
Create file name elasticapm.properties and add content below.# ELK stack APM agent for Java properties. # Config reference: https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html # Enable ELK Agent. enabled=true # Allow ELK Agent collect data from JVM. #recording=true # Service setting. service_name=testing-project application_packages=local.project.testing # APM server settings. server_url=https://elk-server:8200 # Metric collection scale and interval. capture_body=all transaction_sample_rate=0.2 metrics_interval=5m transaction_ignore_urls=/status,/actuator/* enable_log_correlation=true
- Alter execution command.
In dockerfile / service file, alter command as below./usr/bin/java -Delastic.apm.config_file=elasticapm.properties -jar test-service.jar
Reminding
After run dependency check, found in latest version (1.22.0), there are several vulnerabilities found. So split to use -javaagent still a valid option to prevent package polluted.
Leave a Reply