Add a pod template annotation to each pod you want to auto-instrument
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless Observability
Generally available
Stack
Generally available
To auto-instrument a deployment, update its spec.template.metadata.annotations to include the co.elastic.apm/attach key. The webhook matches the value of this key to the webhookConfig.agents value defined in your Helm values file.
For example, if your Webhook values file includes the following:
...
webhookConfig:
agents:
java:
...
Then your co.elastic.apm/attach value should be java:
apiVersion: apps/v1
kind: Deployment
metadata:
# ...
spec:
replicas: 1
template:
metadata:
annotations:
co.elastic.apm/attach: java
labels:
# ...
spec:
#...
- The APM attacher configuration
webhookConfig.agents.javamatchesco.elastic.apm/attach: java. If you define further configurations, for example thejava-devconfiguration below, and you wanted to use that definition for this deployment, this entry would bejava-devinstead ofjava
The spec.template.metadata.annotations value allows you to set custom environment variables and images per deployment. For example, your Helm values file might configure a number of deployments: java-dev might have a different APM environment from java-prod, and backend2 use a different APM agent than other deployments.
agents:
java-dev:
image: docker.elastic.co/observability/apm-agent-java:latest
artifact: "/usr/agent/elastic-apm-agent.jar"
environment:
ELASTIC_APM_SERVER_URL: "http://192.168.1.10:8200"
ELASTIC_APM_ENVIRONMENT: "dev"
ELASTIC_APM_LOG_LEVEL: "debug"
ELASTIC_APM_PROFILING_INFERRED_SPANS_ENABLED: "true"
JAVA_TOOL_OPTIONS: "-javaagent:/elastic/apm/agent/elastic-apm-agent.jar"
java-prod:
image: docker.elastic.co/observability/apm-agent-java:1.44.0
artifact: "/usr/agent/elastic-apm-agent.jar"
environment:
ELASTIC_APM_SERVER_URL: "http://192.168.1.11:8200"
ELASTIC_APM_ENVIRONMENT: "prod"
ELASTIC_APM_LOG_LEVEL: "info"
ELASTIC_APM_PROFILING_INFERRED_SPANS_ENABLED: "true"
JAVA_TOOL_OPTIONS: "-javaagent:/elastic/apm/agent/elastic-apm-agent.jar"
backend2:
image: docker.elastic.co/observability/apm-agent-nodejs:latest
artifact: "/opt/nodejs/node_modules/elastic-apm-node"
environment:
NODE_OPTIONS: "-r /elastic/apm/agent/elastic-apm-node/start"
ELASTIC_APM_SERVER_URL: "http://192.168.1.11:8200"
ELASTIC_APM_SERVICE_NAME: "petclinic"
ELASTIC_APM_LOG_LEVEL: "info"
- The example here shows a
java-prodconfiguration which specifies a specific version of the agent instead of thelatest
The only webhookConfig.agents values defined in values.yaml are java and nodejs. When using other values, you must explicitly specify image, artifact, and *OPTIONS values.
The environment variables defined in the webhook and here take precedence - overwrite - the values defined in the Kubernetes deployments. For example if your image uses JAVA_TOOL_OPTIONS, the value your image sets will be ignored in favour of the value set here or in the values.yaml.