Difficulty: Beginner
Estimated Time: 20 - 30 minutes



Logs and metrics alone are not enough, to really have observability of our applications we need to have Application Performance Mangement with Distributed Tracing, Machine Learning, and Alerting. In this Katacoda scenario we will learn how to enable Elastic APM in a Java application, and then you will add custom instrumentation to a function (the function product()) in that app.

Before you begin the scenario

You will need an Elasticsearch Service in Elastic Cloud (https://cloud.elastic.co). Use an instance that is at least version 6.6.0, as this will include an APM server deployed in Elastic Cloud. Choose a default deployment, as this will include an APM server. If you customize your deployment, make sure that you deploy an APM server. Make sure to record the credentials presented to you during the spin up of your instance so that you can configure your sample application to connect to the APM server, and so that you can authenticate to your Kibana instance.

Let's take a look at the goal

During the scenario you will deploy the sample application in Katacoda and then navigate around in the app. You will then open Kibana (in your Elasticsearch Service instance) and open the APM application. Here is what you will see (assuming that you generated some traffic by opening some of the pages in the app) APM App

Later in the scenario you will add a custom tag to a span, the instructions suggest adding the ProductID as a tag. Here is what that looks like in the APM app in Kibana Tag

A Quick Katacoda Primer

If this is your first time using Katacoda, let me introduce some of the cool ideas:

  • In general, you don't need to type. Most of the time, you can simply click on a command in the instructions to run it.
  • There are a couple steps where you will be directed to edit a file. You can simply click on the blue text on those instruction lines and the file will open in the editor in the top right of the Katacoda window. As you type the changes are saved to disk.

Editor Link

  • There are a couple of times where you will be directed to open Kibana or the sample Java app, clicking on the links provided will open these pages in new tabs.
  • Each time you start or restart a course everything gets reset. If you misconfigure something somehow, simply restart the course.

During this scenario you learned about APM spans, tags, and distributed tracing and the value this brings to you by increasing the observability of your apps. Get more information at https://www.elastic.co/solutions/apm


Step 1 of 5

Create a default Elasticsearch Service in Elastic Cloud instance

As always, take note of the elastic password. All of the rest of the information you can copy later.


Clone the opbeans demo

This version has a modified docker-compose file to use the APM Server in Elastic Cloud.

git clone https://github.com/roncohen/opbeans-java.git /root/course/opbeans

Copy some environment variables

You need two environment variables set to get the APM measurements to your Elasticsearch Service in Elastic Cloud instance. Here is where you get them:


Set the environment variables

Edit the file environment in the Katacoda UI (just click the document icon to the right) and edit with your settings from the above location environment

Source the environment variables: source /root/course/environment

Deploy the opbeans demo

This takes five minutes, maybe longer. Run the command and make a coffee:

Run the compose: cd /root/course/opbeans/ docker-compose -f ./docker-compose-elastic-cloud.yml up

Look at the results in Kibana

  1. When the application has started, generate some traffic by browsing around the site: https://[[HOST_SUBDOMAIN]]-8000-[[KATACODA_HOST]].environments.katacoda.com/
  2. Then go look at the opbeans app in Kibana (in your Elasticsearch Service in Elastic Cloud instance)