Injecting OpenTelemetry with DataKit Operator¶
Starting with v1.9.0, DataKit Operator uses the official OpenTelemetry images to instrument Java, Python, and Node.js applications.
Before You Start¶
Install DataKit Operator and check that application Pods can reach the DataKit endpoints below.
Enable the DataKit OpenTelemetry Input¶
The opentelemetry input must be enabled in DataKit. For example, add opentelemetry to the default enabled input list in the DataKit DaemonSet:
OTLP Traces, Metrics, and Logs use the same DataKit Service and port 9529, but different request paths:
Trace: http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/traces
Metric: http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/metrics
Log: http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/logs
The example rules on this page enable only Traces. To collect Metrics or Logs, change the corresponding OTEL_METRICS_EXPORTER or OTEL_LOGS_EXPORTER from none to otlp; no new DataKit address is required. The application and automatic instrumentation must also be able to produce the corresponding signals.
Choose an injection mode¶
Set the selectors in admission_inject_v2.otels in the Operator YAML. namespace_selectors matches the namespace and label_selectors matches existing Pod labels. Configure at least one list. The Pod must match an entry in each configured list. See selector syntax.
| Scenario | Operator rule | Application workload |
|---|---|---|
| Centrally managed injection | Use check_annotation: false (the field default) and set the version in image. |
Leave the workload YAML unchanged. The rule’s image is used even if the Pod has a version annotation. |
| Opt in per workload | Keep the selectors and set check_annotation: true on the same rule. |
Add or retain the language-specific version annotation under spec.template.metadata.annotations on the target Deployment. Pods outside the selector scope cannot match this rule even with the annotation. |
Supported Runtimes and Images¶
These examples use the injection images below. Other versions are listed on GHCR. Java · Node.js · Python
| Language | Application runtime | Injection image |
|---|---|---|
| Java | Java 8 or later | ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:2.34.0-1 |
| Python | Python 3.10 to 3.14; glibc Linux only | ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.66b2-5 |
| Node.js | Node.js 22.15.0 or later, CommonJS; glibc or Alpine/musl | ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:0.83.0-3 |
Node.js support excludes ESM, bundlers, and custom loaders. The Operator does not detect runtimes. Select Pods that meet the requirements for each language.
Configure Injection Rules¶
Add a rule to admission_inject_v2.otels in the Operator, keeping existing rules in order. The default is []. This Java rule exports traces for Pods in production that already have app=order-service.
{
"admission_inject_v2": {
"otels": [
{
"name": "otel-java",
"language": "java",
"namespace_selectors": ["^production$"],
"label_selectors": ["app=order-service"],
"check_annotation": false,
"image": "ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:2.34.0-1",
"envs": {
"POD_NAME": "{fieldRef:metadata.name}",
"POD_NAMESPACE": "{fieldRef:metadata.namespace}",
"NODE_NAME": "{fieldRef:spec.nodeName}",
"OTEL_SERVICE_NAME": "{fieldRef:metadata.labels['app']}",
"OTEL_RESOURCE_ATTRIBUTES": "k8s.pod.name=$(POD_NAME),k8s.namespace.name=$(POD_NAMESPACE),k8s.node.name=$(NODE_NAME)",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "none",
"OTEL_METRICS_EXPORTER": "none",
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/traces",
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/logs",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "http://datakit-service.datakit.svc.cluster.local:9529/otel/v1/metrics"
},
"resources": {
"requests": {
"cpu": "100m",
"memory": "64Mi"
},
"limits": {
"cpu": "500m",
"memory": "512Mi"
}
}
}
]
}
}
For Python or Node.js, copy the rule, update name and the selectors, set language to python or nodejs, and choose the corresponding image from the image table. All three use the same exporter settings. Keep variables referenced by OTEL_RESOURCE_ATTRIBUTES before it.
Rule Fields¶
| Field | Description |
|---|---|
name |
Rule name, recommended for locating relevant logs |
language |
Required; one of java, python, or nodejs |
namespace_selectors |
Array of Namespace regular expressions |
label_selectors |
Array of Pod Label Selectors |
check_annotation |
Whether the Pod must provide a version Annotation for the corresponding language; defaults to false |
image |
Required; official OpenTelemetry image or a copy in a private registry |
image_pull_policy |
Optional; Always, IfNotPresent, or Never. Missing or invalid values use Always. See Image Pull Policy |
envs |
Environment variables injected into all regular application containers |
resources |
Resource configuration for the init Container; defaults are used when missing or invalid |
For each probe, the Operator uses the first rule in configuration order whose selectors and annotation requirements the Pod meets.
Control Injection with Annotations¶
To disable OTel for one workload, set admission.datakit/otel.enabled: "false" on its Pod template. With "true", the Pod must still meet the rule’s selector and version annotation requirements. To disable all tracing probes, set admission.datakit/tracing.enabled: "false".
When a rule sets check_annotation: true, the Pod must also provide the version Annotation for the corresponding language:
| Language | Version Annotation |
|---|---|
| Java | admission.datakit/otel-java-lib.version |
| Python | admission.datakit/otel-python-lib.version |
| Node.js | admission.datakit/otel-nodejs-lib.version |
The version value replaces only the tag in the rule's image; it does not change the image registry or name. When the platform manages versions centrally, keeping check_annotation: false is recommended.
To let Java workloads with app=order-service in production opt in and choose a version, change check_annotation to true in the example rule and set the tag in the Deployment’s Pod template.
Relationship with Beacon and DDTrace¶
Each Pod receives at most one tracing probe. The Operator checks Beacon → OTel → DDTrace, moving to the next probe only if the current one has no eligible rule. If the target Pods also qualify for Beacon, narrow the Beacon rule or disable it on their Pod template as shown below. When OTel is selected, DDTrace is skipped automatically.
Deployment Example¶
This Deployment matches the Java rule above. Replace example/order-service:1.0.0 with your Java application image before applying it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-service
namespace: production
spec:
replicas: 1
selector:
matchLabels:
app: order-service
template:
metadata:
labels:
app: order-service
spec:
containers:
- name: app
image: example/order-service:1.0.0
ports:
- name: http
containerPort: 8080
Verify Injection and Traces¶
If you edited the ConfigMap directly, restart the Operator first. Recreate the application Pods, then list the init containers for each new Pod.
kubectl -n production get pods -l app=order-service \
-o custom-columns='POD:.metadata.name,INIT:.spec.initContainers[*].name'
Look for datakit-otel-lib-init in the INIT column to confirm injection. Send a request to the application, then filter the trace list in APM by the service name order-service.
For missing injection or init container failures, see General troubleshooting.
- Injection succeeded but no data appears: confirm that the
opentelemetryinput is enabled in DataKit, the OTLP address is reachable, the application framework is supported by automatic instrumentation, and an actual request has been sent. - Rollback is required: remove or disable the OTel rule, then recreate Pods that were already injected.
runAsNonRoot Safeguard¶
If the Operator logs reason=run_as_non_root_without_run_as_user, set runAsUser on the Pod or its first application container to a nonzero UID compatible with the OTel image. Then recreate the Pod.
FAQ¶
What changes in each application container?¶
When a Pod is created, the Operator adds the datakit-otel-lib-init init container and the datakit-otel-auto-instrument EmptyDir. The init container copies the agent. Application containers mount the volume, receive the rule’s envs, and load the agent at startup.
| Language | init Container copy method | Mount and startup environment |
|---|---|---|
| Java | Copies /javaagent.jar from the image to the shared volume |
Mounts /otel-auto-instrumentation-java and appends to JAVA_TOOL_OPTIONS the value -javaagent:/otel-auto-instrumentation-java/javaagent.jar |
| Python | Copies /autoinstrumentation/ from the image to the shared volume |
Mounts /otel-auto-instrumentation-python, adds the automatic initialization and instrumentation directories to the beginning and end of PYTHONPATH, and loads through sitecustomize.py |
| Node.js | Copies /autoinstrumentation/ from the image to the shared volume |
Mounts /otel-auto-instrumentation-nodejs and appends to NODE_OPTIONS the value --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js |
If conflicting startup options prevent injection, check the Operator log for the reason.
DDTrace is a tracing project initiated and open-sourced by Datadog. Copyright belongs to Datadog and other contributors. Guance supports DDTrace data ingestion. Use of DDTrace is subject to the applicable project's open-source license.