Menu
Grafana Cloud

Application Observability Java quickstart

Quickly get started with Application Observability for Java with these easy three steps:

  1. Download the instrumentation agent
  2. Instrument an application
  3. Observe the service in Application Observability

Download the agent

Download the latest jar release of the Grafana OpenTelemetry Distribution for Java.

Instrument an application

Login to Grafana Cloud and follow the following instructions to obtain the necessary information to send telemetry data to Grafana Cloud:

  1. Click Details in the Grafana section on https://grafana.com/profile/org
  2. Copy Instance ID and the last part of Zone into the command below (e.g. prod-eu-west-0 from EU Belgium - gcp europe-west1 - eu - prod-eu-west-0).
  3. On the left menu, click on Security and then on API Keys
  4. Click on Add API Key (MetricsPublisher role) and copy the key into the command below
  5. Choose a Service Name to identify the service (e.g. cart)
  6. Optionally, add attributes to filter data:
    • deployment.environment: Name of the deployment environment (staging or production)
    • service.namespace: A namespace to group similar services (e.g. shop would create shop/cart in Application Observability)
    • service.version: The application version, to see if a new version has introduced a bug
    • service.instance.id: The unique instance, for example the Pod name (a UUID is generated by default)

Add the -javaagent option to the java command with the following environment variables:

shell
export GRAFANA_CLOUD_INSTANCE_ID=<Instance ID>
export GRAFANA_CLOUD_ZONE=<Zone>
export GRAFANA_CLOUD_API_KEY=<API Key>
export OTEL_SERVICE_NAME=<Service Name>
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=<Environment>,service.namespace=<Namespace>,service.version=<Version>
java -javaagent:path/to/grafana-opentelemetry-java.jar -jar myapp.jar

System properties can be used instead of environment variables, for example -Dotel.service.name=<OTEL_SERVICE_NAME> instead of export OTEL_SERVICE_NAME=<OTEL_SERVICE_NAME>

Finally, make some requests to the service to validate data is sent to Grafana Cloud. It might take up to five minutes for data to appear.

Observe the service

In Grafana Cloud, replace the path of the URL with /a/grafana-app-observability-app/services or:

  1. Click on the menu icon in the top left corner
  2. Open the Observability menu
  3. Click on Application

For detailed setup instructions and troubleshooting, refer to the full instrumentation setup documentation.

Example application

See the Grafana OpenTelemetry Java Spring PetClinic configuration for a complete example setup.