Kubernetes Distributed Tracing: Auto-Instrument Services with OpenTelemetry and Debug Traces in OpenObserve

Ready to get started?
Try OpenObserve Cloud today for more efficient and performant observability.

Kubernetes distributed tracing captures how a single request travels through the Pods and Services in your cluster and links each piece of work into one trace. To set it up, auto-instrument your workloads with the OpenTelemetry Operator, send spans to the OpenObserve Gateway Collector, and store, query, and debug them in OpenObserve.
TL;DR
- Run the OpenObserve Kubernetes installer to deploy cert-manager, the OpenTelemetry Operator, the OpenObserve Gateway Collector, and the Kubernetes and instrumentation resources needed to forward traces to OpenObserve.
- Add a logs pipeline to the OpenObserve Gateway Collector so it receives application logs over OTLP and exports them to OpenObserve.
- Configure your Instrumentation resource with the Gateway Collector endpoint and OTLP protocols, then annotate your workloads so the OpenTelemetry Operator injects an auto-instrumentation agent when the Pods are created.
- Send requests to your workloads, view the traces in OpenObserve, and follow them across services to find the slow spans.
- Correlate your application logs with traces in OpenObserve using the
trace_idandspan_id. - If a trace is broken, missing, or incomplete, check instrumentation injection, context propagation, RBAC for Kubernetes metadata, sampling configuration, and Gateway Collector health, in that order.
- Auto-instrumentation covers standard HTTP and library calls, so add manual spans for your custom business logic.
How does distributed tracing work on Kubernetes?
Tracing uses spans and a unique ID (the trace ID) to build the full journey of a request across Pods and Services. It captures how the request executes and how it moves through your cluster. For a deeper introduction to spans, traces, and context, see our distributed tracing guide.
For tracing to work, your application must be instrumented to emit spans, either with the OpenTelemetry SDK or with the agent that the OpenTelemetry Operator injects into your application Pod. Because service interactions span multiple processes, trace context propagation is what keeps those interactions connected. It preserves the parent-child relationship between spans even when a request crosses several processes and services.
A Collector running in the cluster receives these spans, processes them, and exports them to a tracing backend such as OpenObserve, which assembles them into traces, stores them, and lets you query and visualize them.

The tracing pipeline end to end. Spans are created in your app, carry their context across services, pass through the in-cluster Collector, and end up in OpenObserve for searching and analysis.
Which OpenTelemetry Collector deployment pattern should you use for traces?
The OpenTelemetry Collector can run as an agent, as a gateway, or in an agent-to-gateway pattern. The right choice depends on your observability needs, and each pattern places the Collector in a different spot relative to your workloads.
If you're interested in how Prometheus and OpenTelemetry differ in their approach to observability, read our Prometheus vs OpenTelemetry comparison.
These patterns are usually described by the Kubernetes resources that implement them: a DaemonSet, a Deployment, or a sidecar container.
| Pattern. | How it runs. | When to use. | Trade-offs. |
|---|---|---|---|
| DaemonSet (agent). | The Collector runs on every node, and application Pods forward spans to the Collector on their own node. | You want to send traces for your application as well as node-level metrics. | Pods on a node share one Collector, and every node holds its own exporter settings and credentials. |
| Sidecar. | The Collector runs alongside your application's container in the same Pod. | Each workload needs its own Collector and configuration, isolated from everything else. | You manage CPU and memory for every sidecar, which can lead to misallocation. |
| Gateway. | The Collector runs as a Deployment or StatefulSet and acts as a central point for receiving telemetry from your workloads. | You want a straightforward setup with centralized filtering, sampling, policy, and credential management for telemetry from many sources. | It is a single point of failure if it becomes unavailable, and you must scale it as incoming telemetry grows. |
In an agent-to-gateway pattern, Collector agents forward telemetry to a gateway. Teams use this pattern to keep the traces most useful for debugging, applying advanced processing and sampling at the gateway and evaluating traces against configured policies.
For a wider view of how OpenTelemetry and OpenObserve make Kubernetes observability easier, see Simplifying Kubernetes Monitoring with OpenTelemetry and OpenObserve.
Prerequisites
This guide is hands-on. To follow along, you need:.
- A local Kubernetes cluster. This tutorial uses Kind with Kubernetes version 1.37.
- Docker and Helm 4+ installed on your machine.
kubectlinstalled and configured to access your cluster.jqfor inspecting JSON output.- An OpenObserve Cloud account or a self-hosted OpenObserve instance.
What does the demo app look like?
The demo app is an order flow made of three services (frontend, orders, and inventory), each written in a different language. It's small enough to read in a few minutes and behaves like a distributed application you'd debug in production.
One curl command kicks off the whole request chain: the frontend calls the orders service, which checks stock with the inventory service. Three services, three languages, one trace.
- Frontend (Node.js/Express): receives the initial
POST /ordersrequest from a curl command. - Orders (Python/Flask): called by the frontend to process the order (
POST /orders). - Inventory (Java/Spring Boot): called by the orders service to check stock (
POST /inventory).
The inventory service waits 700 ms before it replies to simulate a slow dependency, and it rejects orders for more than 25 items, giving you a second kind of request to compare against smaller orders. It also writes two logs for each request, one when the stock check starts and one when it finishes, so you can jump from a slow inventory span in OpenObserve to the logs for that same request.
The container images for all three services are on Docker Hub, and none of them contain OpenTelemetry code. You'll deploy these images to Kubernetes and let the OpenTelemetry Operator auto-instrument them.
Step 1: Install the OpenTelemetry Operator and the OpenObserve Collector
The OpenTelemetry Operator manages Collector deployments through custom resource definitions (CRDs). OpenObserve provides a single install command that runs a script to install the OpenTelemetry Operator. The script also creates auto-instrumentation resources for tracing and installs cert-manager and the Prometheus Operator CRDs as dependencies. It then deploys the OpenObserve Collector as a Helm release named o2c in the openobserve-collector namespace, preconfigured to collect logs, metrics, and Kubernetes events from your cluster and export them to OpenObserve.
For more on integrating Kubernetes with OpenObserve, see the OpenObserve Kubernetes integration documentation.
The Collector needs to discover and read Kubernetes resources to associate telemetry with the workloads, nodes, and namespaces that produced it. The script therefore creates a ClusterRole and ClusterRoleBinding that grant the Collector read access to Pods, Namespaces, and Nodes. That way, logs, metrics, traces, and Kubernetes events are enriched with metadata such as Pod name, namespace, node, and labels.
- In OpenObserve, open Data sources, select the Recommended tab, and choose Kubernetes.
- Enter the name of your Kubernetes cluster and copy the install command, which is pre-populated with your cluster name, organization, and access key.

The OpenObserve Kubernetes installer with the cluster name pre-populated.
- Run the command in your terminal and give the installation some time to complete:.
curl -sSL https://raw.githubusercontent.com/openobserve/o2-datasource/main/k8s/install.sh | bash -s -- \
--cluster-name=<CLUSTER_NAME> \
--org-id=<O2_ORG> \
--access-key=<ACCESS_KEY> \
--o2-url=https://api.openobserve.ai
When it finishes, you should see a confirmation similar to:.
✓ Check your OpenObserve dashboard for incoming data: https://api.openobserve.ai
- Check that the OpenTelemetry Operator Pod is running:.
kubectl get pods -n opentelemetry-operator-system
Output:.
NAME READY STATUS RESTARTS AGE
opentelemetry-operator-controller-manager-7964645449-fbcfg 1/1 Running 0 175m
- List every resource in the
openobserve-collectornamespace:.
kubectl get all -n openobserve-collector
You should see:.
- One agent Collector Pod per node, running as a DaemonSet.
- A gateway Collector Pod running as a StatefulSet.
- Services exposing OTLP ports 4317 (gRPC) and 4318 (HTTP), monitoring port 8888, and health/extension port 13133.
NAME READY STATUS RESTARTS AGE
pod/o2c-openobserve-collector-agent-collector-9w5r6 1/1 Running 0 160m
pod/o2c-openobserve-collector-agent-collector-mndcj 1/1 Running 0 160m
pod/o2c-openobserve-collector-agent-collector-v25bq 1/1 Running 0 160m
pod/o2c-openobserve-collector-gateway-collector-0 1/1 Running 0 160m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/o2c-openobserve-collector-agent-collector-extension ClusterIP 10.96.198.100 <none> 13133/TCP 160m
service/o2c-openobserve-collector-agent-collector-monitoring ClusterIP 10.96.35.100 <none> 8888/TCP 160m
service/o2c-openobserve-collector-gateway-collector ClusterIP 10.96.100.222 <none> 4317/TCP,4318/TCP 160m
service/o2c-openobserve-collector-gateway-collector-extension ClusterIP 10.96.97.255 <none> 13133/TCP 160m
service/o2c-openobserve-collector-gateway-collector-headless ClusterIP None <none> 4317/TCP,4318/TCP 160m
service/o2c-openobserve-collector-gateway-collector-monitoring ClusterIP 10.96.71.203 <none> 8888/TCP 160m
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/o2c-openobserve-collector-agent-collector 3 3 3 3 3 <none> 160m
NAME READY AGE
statefulset.apps/o2c-openobserve-collector-gateway-collector 1/1 160m
The agent Collector gathers telemetry locally on each node, while the gateway Collector receives OTLP telemetry on ports 4317 and 4318 and forwards it to OpenObserve.
- List the auto-instrumentation resources the installer created:.
kubectl get instrumentation -n openobserve-collector
Each one is language-specific and lets the OpenTelemetry Operator inject instrumentation into the workloads you select.
Output:.
NAME AGE ENDPOINT SAMPLER SAMPLER ARG
openobserve-dotnet 169m http://o2c-openobserve-collector-gateway-collector.openobserve-collector.svc.cluster.local:4318 parentbased_traceidratio 1.0
openobserve-go 169m http://o2c-openobserve-collector-gateway-collector.openobserve-collector.svc.cluster.local:4318 parentbased_traceidratio 1.0
openobserve-java 169m http://o2c-openobserve-collector-gateway-collector.openobserve-collector.svc.cluster.local:4318 parentbased_traceidratio 1.0
openobserve-nodejs 169m http://o2c-openobserve-collector-gateway-collector.openobserve-collector.svc.cluster.local:4318 parentbased_traceidratio 1.0
openobserve-python 169m http://o2c-openobserve-collector-gateway-collector.openobserve-collector.svc.cluster.local:4318 parentbased_traceidratio 1.0
- Check that the OpenTelemetry Operator registered its custom resource definitions:.
kubectl get crd | grep opentelemetry
Output:.
instrumentations.opentelemetry.io Namespaced v1alpha1(storage) 2026-11-21T09:46:48Z
opampbridges.opentelemetry.io Namespaced v1alpha1(storage) 2026-11-21T09:46:48Z
opentelemetrycollectors.opentelemetry.io Namespaced v1alpha1,v1beta1(storage) 2026-11-21T09:46:49Z
targetallocators.opentelemetry.io Namespaced v1alpha1(storage) 2026-11-21T09:46:49Z
Each of these CRDs extends the Kubernetes API with a distinct resource type that the Operator reconciles.
- Verify that cert-manager is installed and its Pods are running:.
kubectl get pods -n cert-manager
Output:.
NAME READY STATUS RESTARTS AGE
cert-manager-58b55f7787-nvdgg 1/1 Running 0 4h54m
cert-manager-cainjector-7849d847-rq7fm 1/1 Running 0 4h54m
cert-manager-webhook-67cb557ddd-tvpjb 1/1 Running 0 4h54m
- Confirm that the ClusterRole and ClusterRoleBinding that give the Collector read access to cluster resources exist:.
kubectl get clusterrole,clusterrolebinding | grep -iE 'o2c|openobserve'
Output:.
clusterrole.rbac.authorization.k8s.io/o2c-openobserve-collector 2026-11-21T09:47:38Z
clusterrolebinding.rbac.authorization.k8s.io/o2c-openobserve-collector ClusterRole/o2c-openobserve-collector 6h19m
In OpenObserve, once the installation completes, the Verify data in OpenObserve step of the Data sources page shows a green New data received message with the number of records that arrived in the default stream from your cluster.

Data received from the cluster, confirmed on the Data sources page.
Step 2: Add a logs pipeline to the OpenObserve Gateway Collector
At the time of writing, the OpenObserve Gateway Collector deployed by the Kubernetes installer does not include a logs pipeline for receiving application logs over OTLP. For the demo app, you want to export traces and logs, as well as node-level metrics, to OpenObserve.
- Create an override file (
values.yaml) that adds a logs pipeline to the OpenObserve Gateway Collector:.
cat <<EOF > values.yaml
gateway:
service:
pipelines:
logs:
receivers:
- otlp
processors:
- memory_limiter
- resourcedetection
- attributes
- k8sattributes
- batch
exporters:
- otlphttp/openobserve
EOF
- Upgrade the existing OpenObserve Collector Helm release with the override file:.
helm upgrade o2c openobserve/openobserve-collector \
--version 0.9.0 \
-n openobserve-collector \
--reuse-values \
-f values.yaml
Output:.
Release "o2c" has been upgraded. Happy Helming!
NAME: o2c
LAST DEPLOYED: Tue Nov 24 12:00:28 2026
NAMESPACE: openobserve-collector
STATUS: deployed
REVISION: 2
DESCRIPTION: Upgrade complete
TEST SUITE: None
NOTES:
If everything proceeded without errors then your cluster is now sending logs and metrics to OpenObserve.
...
- Confirm that Helm applied the logs pipeline to the Gateway Collector:.
kubectl get opentelemetrycollector \
o2c-openobserve-collector-gateway \
-n openobserve-collector \
-o json | jq '.spec.config.service.pipelines'
Output:.
"logs": {
"exporters": [
"otlphttp/openobserve"
],
"processors": [
"memory_limiter",
"resourcedetection",
"attributes",
"k8sattributes",
"batch"
],
"receivers": [
"otlp"
]
}
- Patch the
openobserve-javaInstrumentation resource so the Java agent exports logs over OTLP:.
kubectl patch instrumentation openobserve-java \
-n openobserve-collector \
--type=merge \
-p='{
"spec": {
"java": {
"env": [
{
"name": "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_LOGS_EXPORTER",
"value": "otlp"
}
]
}
}
}'
Output:.
instrumentation.opentelemetry.io/openobserve-java patched
You can verify the change with:.
kubectl get instrumentation openobserve-java \
-n openobserve-collector \
-o json | jq '.spec.java.env'
Output:.
[
{
"name": "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL",
"value": "http/protobuf"
},
{
"name": "OTEL_LOGS_EXPORTER",
"value": "otlp"
}
]
Step 3: Auto-instrument workloads with the Instrumentation resource
The OpenTelemetry Operator uses the Instrumentation custom resource to inject an OpenTelemetry auto-instrumentation agent into Pods. The agent runs as an init container and copies a language-specific instrumentation library into a shared volume that your application loads at startup. For another walkthrough of zero-code instrumentation across services, see auto-instrumenting microservices with OpenTelemetry.
- Deploy the demo app with the auto-instrumentation Pod annotations:.
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
selector:
app: frontend
ports:
- name: http
port: 3000
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
annotations:
instrumentation.opentelemetry.io/inject-nodejs: "openobserve-collector/openobserve-nodejs"
spec:
containers:
- name: frontend
image: mercybassey/otel-demo-frontend:1.0.0
ports:
- containerPort: 3000
env:
- name: ORDERS_URL
value: http://orders.default.svc.cluster.local:8000/orders
---
apiVersion: v1
kind: Service
metadata:
name: orders
spec:
selector:
app: orders
ports:
- name: http
port: 8000
targetPort: 8000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders
spec:
replicas: 1
selector:
matchLabels:
app: orders
template:
metadata:
labels:
app: orders
annotations:
instrumentation.opentelemetry.io/inject-python: "openobserve-collector/openobserve-python"
spec:
containers:
- name: orders
image: mercybassey/otel-demo-orders:1.0.0
ports:
- containerPort: 8000
env:
- name: INVENTORY_URL
value: http://inventory.default.svc.cluster.local:8080/inventory
---
apiVersion: v1
kind: Service
metadata:
name: inventory
spec:
selector:
app: inventory
ports:
- name: http
port: 8080
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: inventory
spec:
replicas: 1
selector:
matchLabels:
app: inventory
template:
metadata:
labels:
app: inventory
annotations:
instrumentation.opentelemetry.io/inject-java: "openobserve-collector/openobserve-java"
spec:
containers:
- name: inventory
image: mercybassey/otel-demo-inventory:1.0.1
ports:
- containerPort: 8080
EOF
- Confirm that all Pods are running:.
kubectl get pods
If you see the following output, the instrumentation agent is being injected:.
NAME READY STATUS RESTARTS AGE
frontend-547d6b897f-ssjwf 0/1 Init:0/1 0 23s
inventory-6976466665-2szsm 0/1 Init:0/1 0 23s
orders-64c4b4b9d6-dcmbg 0/1 Init:0/1 0 23s
Once the status is Running, your Pods are instrumented and ready to emit spans:.
NAME READY STATUS RESTARTS AGE
frontend-547d6b897f-ssjwf 1/1 Running 0 3m51s
inventory-6976466665-2szsm 1/1 Running 0 3m51s
orders-64c4b4b9d6-dcmbg 1/1 Running 0 3m51s
Step 4: View and debug a trace in OpenObserve
The frontend service is the entry point to the demo app. Forward its port to your local machine, generate some orders, and view them in OpenObserve.
- Create a connection to the frontend Service with port forwarding:.
kubectl port-forward svc/frontend 3000:3000
- In another terminal, submit an order:.
curl -X POST http://localhost:3000/orders -H "Content-Type: application/json" -d '{"item":"keyboard","quantity":5}'
- Optionally, send a few more to create traces you can compare:.
for i in $(seq 1 5); do
curl -sS -X POST http://localhost:3000/orders \
-H "Content-Type: application/json" \
-d '{"item":"keyboard","quantity":3}'
echo
sleep 1
done
In OpenObserve, open Traces, select the stream receiving your spans (this guide uses the default stream), and view the requests you just sent.

The Traces view in OpenObserve. Each row is one request sent to the frontend, with its timestamp, duration, span count, and status.
Find the slow span in the trace waterfall
Look at the Duration column and open the trace waterfall for one of the longest-running requests, for example the one that took 809.08 ms.

The trace waterfall for an 809.08 ms request. The inventory span accounts for 733.16 ms of the total, which makes it the first candidate for optimization.
The inventory span takes 733.16 ms of the 809.08 ms request, so about 90.6% of the end-to-end latency comes from one slow dependency in the inventory service, and everything else is small by comparison. A span like this is your first candidate for optimization, for example by caching or parallelizing the dependency.
Identify the Pod that handled the request from span attributes
Inspect the inventory span's attributes and note its Pod name and namespace so you can identify the workload that handled the request.

The inventory span attributes in OpenObserve. The highlighted fields show the Kubernetes namespace, node name, and Pod name of the workload that handled the request.
In this example, the Pod name is inventory-6976466665-jz4xg, and it runs on the node kind-worker2 in the default namespace.
Correlate logs with the trace using trace_id
To see what the services were doing during that request, select Logs from the left menu and query log entries by trace ID, for example trace_id='bde05ad0d3898c001bfec4eb9ec696ad'. OpenObserve returns the log lines written while the services handled that request. Our guide to correlating logs, metrics, and traces covers this workflow in more depth.

The Logs page filtered by trace_id. The two entries are the inventory service's log lines for the same request seen in the trace waterfall.
Why are traces broken or missing on Kubernetes?
Traces can break and show up missing or incomplete. The table below maps each symptom to what to check and how to fix it.
| Symptom. | What to check. | Fix or next step. |
|---|---|---|
| Missing Kubernetes attributes. | Collector permissions, Pod annotations, and the attributes the application already supplies. | Grant the Collector read access to the needed Kubernetes resources, then confirm a new span is enriched. |
| Pod has no init container. | The Pod annotation, the Instrumentation resource it references, and the Operator logs. | Correct the configuration and recreate the Pod. |
| Spans drop as traffic increases. | Collector restarts and OOMKilled events, exporter failures, and batch settings. |
Check CPU and memory usage under real load, and adjust batch limits accordingly. |
| Fewer traces than requests. | The head and tail sampling policies in your deployment. | Head sampling decides to keep or drop a request at the start, tail sampling at the end. Align your sampling policies with what you actually want to see. |
The Collector's own telemetry helps you tell receive, processing, and export problems apart, so always check the Collector logs for errors or warnings. Here are three common failures.
Missing init container
kubectl get pods -n default -l app=inventory -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.initContainers[*].name}{"\n"}{end}'
A Pod that was not instrumented prints only its name:.
inventory-7fdcfdd59-w6ftm
An instrumented Pod also lists the injected init container:.
inventory-7fdcfdd59-w6ftm opentelemetry-auto-instrumentation-java
Incomplete trace waterfall

The request succeeds, but the waterfall is incomplete: orders records its inventory call, while inventory emits no span.
Missing Kubernetes attributes caused by RBAC
E1104 14:36:30.649110 1 reflector.go:227] "Failed to watch" err="failed to list *v1.Pod: pods is forbidden: User \"system:serviceaccount:default:otel-collector-collector\" cannot list resource \"pods\" in API group \"\" at the cluster scope" logger="UnhandledError" reflector="k8s.io/client-go@v0.37.0/tools/cache/reflector.go:343" type="*v1.Pod"
When should you add manual instrumentation?
Auto-instrumentation falls short for custom business logic. It captures common library operations, but operations such as order validation, discount calculation, or reserving stock need their own spans.
The code below adds an inventory.check_stock span that records how long the stock check takes, the quantity requested, and whether stock is available. For more on the Java SDK, see our guide to distributed tracing in Java.
var tracer = io.opentelemetry.api.GlobalOpenTelemetry
.getTracer("demo.inventory");
var span = tracer.spanBuilder("inventory.check_stock").startSpan();
boolean available;
try (var scope = span.makeCurrent()) {
Thread.sleep(700);
available = quantity > 0 && quantity <= 25;
span.setAttribute("inventory.quantity", quantity);
span.setAttribute("inventory.available", available);
} finally {
span.end();
}
Get started with OpenObserve
Distributed tracing gives you visibility into the services and dependencies responsible for errors and latency. Use auto-instrumentation for common requests, and add manual instrumentation when you need visibility into custom business logic.
- Try the same setup in OpenObserve Cloud with a 14-day free trial, and start exploring your own traces and logs.
- Read the OpenObserve Kubernetes integration docs for advanced installation options.
- Related reading: Kubernetes monitoring with OpenTelemetry and Prometheus.
Frequently Asked Questions
About the Author
Follow OpenObserve on Google
Add OpenObserve as a preferred source to see more of our articles in Google Search and Top Stories.












