How to use OCI APM in Kubernetes Environment for Java Application

Karthic
3 min readApr 22, 2024

--

I have chosen Azure Kubernetes to demonstrate OCI APM will work on other cloud Kubernetes environment as well.

Azure Kubernetes

If you have not created please create one APM Domain in Oracle Cloud .You can create a free domain for testing purpose.

We will use the OTEL Kubernetes Operator for Instrumentation.

Install cert-manager which is a pre-requisite. As of this writing 1.14.4 is the latest version.

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.4/cert-manager.yaml

Install the Operator by running the below kubectl command.

kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

The operator can inject and configure OpenTelemetry auto-instrumentation libraries.
Currently Apache HTTPD, DotNet, Go, Java, Nginx, NodeJS and Python are supported.

Instead of the default OpenTelemetry java instrumentation we will use oracle APM java agent instrumentation as custom instrumentation.This provides Real user monitoring and other extra capabilities for java application.

We need to create Instrumentation as a custom resource for auto-injection.

Create a secret to store the APM private key which you can retrieve from APM Administration->APM Domain →Data keys page in Oracle cloud console.

kubectl create secret generic otelinst — from-literal=privkey=<auto_generated_private_datakey>

apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: inst-apm-java
namespace: opentelemetry-operator-system
spec:
java:
image: us-ashburn-1.ocir.io/idpyjkbcc9tk/apm-java-agent-aio:latest
env:
- name: OTEL_com_oracle_apm_agent_data_upload_endpoint
value: <data-upload-endpoint>
- name: OTEL_com_oracle_apm_agent_private_data_key
valueFrom:
secretKeyRef:
name: otelinst
key: privkey
- name: OTEL_com_oracle_apm_agent_rum_enable_injection
value: "true"
- name: OTEL_com_oracle_apm_agent_rum_web_application
value: "Petclinic"
- name: OTEL_com_oracle_apm_agent_public_data_key
value: <publickey>

I have used a sample petclinic app available in dockerhub just for testing. Please use the application you are familiar with .

kubectl create deployment petclinic — image=ikolaxis/petclinic:java11-openj9

For auto-instrumentation we need to add an annotation either to the deployment or if we want to apply for all the pods in the namespace you can apply the annotation to the namespace.

kubectl annotate namespace <namespacename> instrumentation.opentelemetry.io/inject-java=<namespace>/<Instrumentation CR name>

kubectl annotate namespace default instrumentation.opentelemetry.io/inject-java=opentelemetry-operator-system/inst-apm-java

If all the setup is successful you will see the traces flowing into Oracle APM tool when you access the application.You can access the application in local browser using port-forwarding

kubectl port-forward <podname> 8080:8080 &

If there is any issue please shell into the pod and look for the the logs under oracle-apm-agent/log /<podname> directory.

Sample PetClinic App
Trace Explorer
Browser Session Details

Reference :
Oracle Blog
Oracle Application performance Monitoring

--

--

No responses yet