DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Snake-Based REST API (Python, Mamba, Hydra, and Fast API)
  • Writing a Chat With Akka
  • Surprisingly Simple Tools to Help You Smash API-First Approach
  • Penetration Test Types for (REST) API Security Tests

Trending

  • Understanding Java Signals
  • Solid Testing Strategies for Salesforce Releases
  • Ensuring Configuration Consistency Across Global Data Centers
  • Grafana Loki Fundamentals and Architecture
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Why and How To Integrate Elastic APM in Apache JMeter

Why and How To Integrate Elastic APM in Apache JMeter

Explore how and why to integrate Elastic APM to add the notion of pages from JMeter in Kibana APM dashboards and how to use the jmeter-elastic-apm tool.

By 
Vincent DABURON user avatar
Vincent DABURON
·
May. 07, 24 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
2.9K Views

Join the DZone community and get the full member experience.

Join For Free

The Advantages of Elastic APM for Observing the Tested Environment

My first use of the Elastic Application Performance Monitoring (Elastic APM) solution coincides with projects that were developed based on microservices in 2019 for the projects on which I was responsible for performance testing.

At that time (2019) the first versions of Elastic APM were released.

I was attracted by the easy installation of agents, the numerous protocols supported by the Java agent (see Elastic supported technologies) including the Apache HttpClient used in JMeter and other languages (Go, .NET, Node.js, PHP, Python, Ruby), and the quality of the dashboard in Kibana for the APM. I found the information displayed in the Kibana APM dashboards to be relevant and not too verbose. The Java agent monitoring is simple but displays essential information on the machine's OS and JVM. The open-source aspect and the free solution for the main functions of the tool were also decisive.

I generalize the use of the Elastic APM solution in performance environments for all projects. With Elastic APM, I have the timelines of the different calls and exchanges between web services, the SQL queries executed, the exchange of messages by JMS file, and monitoring. I also have quick access to errors or exceptions thrown in Java applications.

Why Integrate Elastic APM in Apache JMeter

By adding Java APM Agents to web applications, we find the services called timelines in the Kibana dashboards. However, we remain at a REST API call level mainly, because we do not have the notion of a page.

For example, page PAGE01 will make the following API calls:

 
/rest/service1
/rest/service2
/rest/service3


On another page, PAGE02 will make the following calls:

 
/rest/service2
/rest/service4
/rest/service5
/rest/service6


The third page, PAGE03, will make the following calls:

 
/rest/service1
/rest/service2
/rest/service4


In this example, service2 is called on 3 different pages and service4 in 2 pages.

If we look in the Kibana dashboard for service2, we will find the union of the calls of the 3 calls corresponding to the 3 pages, but we don't have the notion of a page.

We cannot answer "In this page, what is the breakdown of time in the different REST calls," because for a user of the application, the notion of page response time is important.

The goal of the jmeter-elastic-apm tool is to add the notion of an existing page in JMeter in the Transaction Controller. This starts in JMeter by creating an APM transaction, and then propagating this transaction identifier (traceparent) with the Elastic agent to an HTTP REST request to web services because the APM Agent recognizes the Apache HttpClient library and can instrument it.

In the HTTP request, the APM Agent will add the identifier of the APM transaction to the header of the HTTP request. The headers added are traceparent and elastic-apm-traceparent.
Added headers: traceparent and elastic-apm-traceparent


JMeter dashboard

We start from the notion of the page in JMeter (Transaction Controller) to go to the HTTP calls of the web application (gestdoc) hosted in Tomcat.

Timeline for JMeter Transaction Controller

In the case of an application composed of multi-web services, we will see in the timeline the different web services called in HTTP(s) or JMS and the time spent in each web service.

This is an example of technical architecture for a performance test with Apache JMeter and Elastic APM Agent to test a web application hosted in Apache Tomcat.

Example of technical architecture for a performance test with Apache JMeter and ELASTIC APM Agent to test a web application hosted in Apache Tomcat

How the jmeter-elastic-apm Tool Works

jmeter-elastic-apm adds Groovy code before a JMeter Transaction Controller to create an APM transaction before a page.

In the JMeter Transaction Controller, we find HTTP samplers that make REST HTTP(s) calls to the services. The Elastic APM Agent automatically adds a new traceparent header containing the identifier of the APM transaction because it recognizes the Apache HttpClient of the HTTP sampler.

The Groovy code terminates the APM transaction to indicate the end of the page.

The jmeter-elastic-apm tool automates the addition of Groovy code before and after the JMeter Transaction Controller.

The jmeter-elastic-apm tool is open source on GitHub (see link in the Conclusion section of this article).

This JMeter script is simple with 3 pages in 3 JMeter Transaction Controllers.
Simple JMeter script with 3 pages in 3 JMeter Transaction Controllers

After launching the jmeter-elastic-apm action ADD tool, the JMeter Transaction Controllers are surrounded by Groovy code to create an APM transaction before the JMeter Transaction Controller and close the APM transaction after the JMeter Transaction Controller.

Launching the jmeter-elastic-apm action ADD too

In the “groovy begin transaction apm” sampler, the Groovy code calls the Elastic APM API (simplified version):

Groovy
 
Transaction transaction = ElasticApm.startTransaction();
Scope scope = transaction.activate();
transaction.setName(transactionName); // contains JMeter Transaction Controller Name


In the “groovy end transaction apm” sampler, the groovy code calls the ElasticApm API (simplified version):

Groovy
 
transaction.end();


Configuring Apache JMeter With the Elastic APM Agent and the APM Library

Start Apache JMeter With Elastic APM Agent and Elastic APM API Library

  1. Declare the Elastic APM Agent URLto find the APM Agent:
    • Add the ELASTIC APM Agent somewhere in the filesystem (could be in the <JMETER_HOME>\lib but not mandatory).
    • In <JMETER_HOME>\bin, modify the jmeter.bat or setenv.bat.
    • Add Elastic APM configuration like so:
Shell
 
set APM_SERVICE_NAME=yourServiceName
set APM_ENVIRONMENT=yourEnvironment
set APM_SERVER_URL=http://apm_host:8200

set JVM_ARGS=-javaagent:<PATH_TO_AGENT_APM_JAR>\elastic-apm-agent-<version>.jar -Delastic.apm.service_name=%APM_SERVICE_NAME% -Delastic.apm.environment=%APM_ENVIRONMENT% -Delastic.apm.server_urls=%APM_SERVER_URL%


2. Add the Elastic APM library:

  • Add the Elastic APM API library to the <JMETER_HOME>\lib\apm-agent-api-<version>.jar.
  • This library is used by JSR223 Groovy code.
  • Use this URL to find the APM library.

Recommendations on the Impact of Adding Elastic APM in JMeter

The APM Agent will intercept and modify all HTTP sampler calls, and this information will be stored in Elasticsearch.

It is preferable to voluntarily disable the HTTP request of static elements (images, CSS, JavaScript, fonts, etc.) which can generate a large number of requests but are not very useful in analyzing the timeline.

In the case of heavy load testing, it's recommended to change the elastic.apm.transaction_sample_rate parameter to only take part of the calls so as not to saturate the APM Server and Elasticsearch.

This elastic.apm.transaction_sample_rate parameter can be declared in <JMETER_HOME>\jmeter.bat or setenv.bat but also in a JSR223 sampler with a short Groovy code in a setUp thread group.

Groovy code records only 50% samples:

Groovy
 
import co.elastic.apm.api.ElasticApm;
// update elastic.apm.transaction_sample_rate
ElasticApm.setConfig("transaction_sample_rate","0.5");


Conclusion

The jmeter-elastic-apm tool allows you to easily integrate the Elastic APM solution into JMeter and add the notion of a page in the timelines of Kibana APM dashboards.

Elastic APM + Apache JMeter is an excellent solution for understanding how the environment works during a performance test with simple monitoring, quality dashboards, time breakdown timelines in the different distributed application layers, and the display of exceptions in web services.

Over time, the Elastic APM solution only gets better. I strongly recommend it, of course, in a performance testing context, but it also has many advantages in the context of a development environment used for developers or integration used by functional or technical testers.

Links

  • Command Line Tool jmeter-elastic-apm
  • JMeter plugin elastic-apm-jmeter-plugin
  • Elastic APM Guides: APM Guide or Application performance monitoring (APM)
API Apache JMeter Open source REST Groovy (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Snake-Based REST API (Python, Mamba, Hydra, and Fast API)
  • Writing a Chat With Akka
  • Surprisingly Simple Tools to Help You Smash API-First Approach
  • Penetration Test Types for (REST) API Security Tests

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!