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

> Set up distributed tracing on Kubernetes with the OpenTelemetry Operator, auto-instrument three services, and debug slow spans and logs in OpenObserve.

Source: https://openobserve.ai/blog/kubernetes-distributed-tracing-opentelemetry/
Published: 2026-12-04
Authors: Mercy Bassey
Category: How To
Tags: OpenObserve, Kubernetes, OpenTelemetry, Tracing, Logging, 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_id` and `span_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](/blog/distributed-tracing-basics-to-beyond-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.

![Kubernetes distributed tracing pipeline: spans created by manual or auto-instrumentation propagate trace context between services, pass through the in-cluster OpenTelemetry Collector, and are stored and queried in OpenObserve](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image1.png)

*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](https://opentelemetry.io/docs/collector/deploy/other/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](/blog/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](/blog/monitoring-kubernetes-with-opentelemetry/).*

## 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](https://docs.docker.com/engine/install) and [Helm 4+](https://helm.sh/docs/intro/install/) installed on your machine.
- `kubectl` installed and configured to access your cluster.
- `jq` for inspecting JSON output.
- An [OpenObserve Cloud](https://cloud.openobserve.ai) 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.

<div class="not-prose my-8" style="overflow-x:auto">
<svg width="100%" style="min-width:680px" viewBox="0 0 860 220" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Demo app request flow: a curl command sends POST /orders to the frontend service (Node.js, Express), which calls the orders service (Python, Flask) with POST /orders, which calls the inventory service (Java, Spring Boot) with POST /inventory, all in the default namespace of a Kubernetes cluster.">
<defs><marker id="k8st-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0,0 L10,5 L0,10 z" fill="#6B7280"/></marker></defs>
<rect x="0.5" y="0.5" width="859" height="219" rx="12" fill="#ffffff" stroke="#E5E7EB"/>
<g font-family="Inter, sans-serif">
<rect x="30" y="85" width="110" height="64" rx="8" fill="#F3F4F6" stroke="#D1D5DB"/>
<text x="85" y="113" text-anchor="middle" font-size="14" font-weight="600" fill="#1E1E1E">You</text>
<text x="85" y="133" text-anchor="middle" font-size="12" fill="#4B5563">curl</text>
<rect x="170" y="30" width="670" height="165" rx="14" fill="#F5F3FF" stroke="#8B5CF6" stroke-dasharray="6 5"/>
<text x="190" y="56" font-size="13" fill="#4B5563">Kubernetes cluster, namespace: default</text>
<rect x="195" y="78" width="180" height="82" rx="8" fill="#ffffff" stroke="#8B5CF6"/>
<text x="285" y="104" text-anchor="middle" font-size="14" font-weight="600" fill="#1E1E1E">frontend</text>
<text x="285" y="124" text-anchor="middle" font-size="12" fill="#4B5563">Node.js, Express</text>
<text x="285" y="144" text-anchor="middle" font-size="12" font-family="ui-monospace, monospace" fill="#6D28D9">POST /orders</text>
<rect x="420" y="78" width="180" height="82" rx="8" fill="#ffffff" stroke="#8B5CF6"/>
<text x="510" y="104" text-anchor="middle" font-size="14" font-weight="600" fill="#1E1E1E">orders</text>
<text x="510" y="124" text-anchor="middle" font-size="12" fill="#4B5563">Python, Flask</text>
<text x="510" y="144" text-anchor="middle" font-size="12" font-family="ui-monospace, monospace" fill="#6D28D9">POST /orders</text>
<rect x="645" y="78" width="180" height="82" rx="8" fill="#ffffff" stroke="#8B5CF6"/>
<text x="735" y="104" text-anchor="middle" font-size="14" font-weight="600" fill="#1E1E1E">inventory</text>
<text x="735" y="124" text-anchor="middle" font-size="12" fill="#4B5563">Java, Spring Boot</text>
<text x="735" y="144" text-anchor="middle" font-size="12" font-family="ui-monospace, monospace" fill="#6D28D9">POST /inventory</text>
<line x1="140" y1="117" x2="190" y2="117" stroke="#6B7280" stroke-width="2" marker-end="url(#k8st-arrow)"/>
<line x1="375" y1="119" x2="415" y2="119" stroke="#6B7280" stroke-width="2" marker-end="url(#k8st-arrow)"/>
<line x1="600" y1="119" x2="640" y2="119" stroke="#6B7280" stroke-width="2" marker-end="url(#k8st-arrow)"/>
<text x="735" y="182" text-anchor="middle" font-size="11" fill="#6B7280">waits 700 ms, rejects quantity &gt; 25</text>
</g>
</svg>
</div>

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.

1. **Frontend (Node.js/Express):** receives the initial `POST /orders` request from a curl command.
2. **Orders (Python/Flask):** called by the frontend to process the order (`POST /orders`).
3. **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](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) (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](https://openobserve.ai/docs/integration/system/k8s/).*

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.

1. In OpenObserve, open **Data sources**, select the **Recommended** tab, and choose **Kubernetes**.
2. Enter the name of your Kubernetes cluster and copy the install command, which is pre-populated with your cluster name, organization, and access key.

![OpenObserve Kubernetes data source page with the cluster name entered and the copy button for the pre-populated install command](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image2.png)

*The OpenObserve Kubernetes installer with the cluster name pre-populated.*

3. Run the command in your terminal and give the installation some time to complete:

```bash
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:

```text
✓ Check your OpenObserve dashboard for incoming data: https://api.openobserve.ai
```

4. Check that the OpenTelemetry Operator Pod is running:

```bash
kubectl get pods -n opentelemetry-operator-system
```

Output:

```text
NAME                                                         READY   STATUS    RESTARTS   AGE
opentelemetry-operator-controller-manager-7964645449-fbcfg   1/1     Running   0          175m
```

5. List every resource in the `openobserve-collector` namespace:

```bash
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.

```text
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.

6. List the auto-instrumentation resources the installer created:

```bash
kubectl get instrumentation -n openobserve-collector
```

Each one is language-specific and lets the OpenTelemetry Operator inject instrumentation into the workloads you select.

Output:

```text
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
```

7. Check that the OpenTelemetry Operator registered its custom resource definitions:

```bash
kubectl get crd | grep opentelemetry
```

Output:

```text
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.

8. Verify that cert-manager is installed and its Pods are running:

```bash
kubectl get pods -n cert-manager
```

Output:

```text
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
```

9. Confirm that the ClusterRole and ClusterRoleBinding that give the Collector read access to cluster resources exist:

```bash
kubectl get clusterrole,clusterrolebinding | grep -iE 'o2c|openobserve'
```

Output:

```text
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.

![OpenObserve Data sources page showing New data received with 10,510 records in the default stream from the k8s-distributed-tracing cluster](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image3.png)

*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.

1. Create an override file (`values.yaml`) that adds a logs pipeline to the OpenObserve Gateway Collector:

```bash
cat <<EOF > values.yaml
gateway:
  service:
    pipelines:
      logs:
        receivers:
          - otlp
        processors:
          - memory_limiter
          - resourcedetection
          - attributes
          - k8sattributes
          - batch
        exporters:
          - otlphttp/openobserve
EOF
```

2. Upgrade the existing OpenObserve Collector Helm release with the override file:

```bash
helm upgrade o2c openobserve/openobserve-collector \
  --version 0.9.0 \
  -n openobserve-collector \
  --reuse-values \
  -f values.yaml
```

Output:

```text
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.
...
```

3. Confirm that Helm applied the logs pipeline to the Gateway Collector:

```bash
kubectl get opentelemetrycollector \
  o2c-openobserve-collector-gateway \
  -n openobserve-collector \
  -o json | jq '.spec.config.service.pipelines'
```

Output:

```json
"logs": {
    "exporters": [
      "otlphttp/openobserve"
    ],
    "processors": [
      "memory_limiter",
      "resourcedetection",
      "attributes",
      "k8sattributes",
      "batch"
    ],
    "receivers": [
      "otlp"
    ]
  }
```

4. Patch the `openobserve-java` Instrumentation resource so the Java agent exports logs over OTLP:

```bash
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:

```text
instrumentation.opentelemetry.io/openobserve-java patched
```

You can verify the change with:

```bash
kubectl get instrumentation openobserve-java \
  -n openobserve-collector \
  -o json | jq '.spec.java.env'
```

Output:

```json
[
  {
    "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](/blog/how-to-auto-instrument-distributed-services/).

1. Deploy the demo app with the auto-instrumentation Pod annotations:

```bash
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
```

2. Confirm that all Pods are running:

```bash
kubectl get pods
```

If you see the following output, the instrumentation agent is being injected:

```text
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:

```text
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.

1. Create a connection to the frontend Service with port forwarding:

```bash
kubectl port-forward svc/frontend 3000:3000
```

2. In another terminal, submit an order:

```bash
curl -X POST http://localhost:3000/orders -H "Content-Type: application/json" -d '{"item":"keyboard","quantity":5}'
```

3. Optionally, send a few more to create traces you can compare:

```bash
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.

![OpenObserve Traces page for the default stream listing seven frontend requests with timestamp, operation, duration, span count, and SUCCESS status](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image4.png)

*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.

![OpenObserve trace waterfall for an 809.08 ms POST request across frontend, orders, and inventory, with the inventory span taking 733.16 ms](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image5.png)

*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.

![OpenObserve inventory span attributes highlighting service_k8s_namespace_name default, service_k8s_node_name kind-worker2, and service_k8s_pod_name inventory-6976466665-jz4xg](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image6.png)

*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](/blog/logs-traces-metrics-correlation/) covers this workflow in more depth.

![OpenObserve Logs page filtered by trace_id showing two inventory service log entries with the same span_id and trace_id as the slow span](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image7.png)

*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

```bash
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:

```text
inventory-7fdcfdd59-w6ftm
```

An instrumented Pod also lists the injected init container:

```text
inventory-7fdcfdd59-w6ftm	opentelemetry-auto-instrumentation-java
```

### Incomplete trace waterfall

![OpenObserve trace waterfall where the orders service records its call to inventory but the inventory service emits no span](/assets/blog/kubernetes-distributed-tracing-opentelemetry/image8.png)

*The request succeeds, but the waterfall is incomplete: orders records its inventory call, while inventory emits no span.*

### Missing Kubernetes attributes caused by RBAC

```text
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](/blog/distributed-tracing-java/).

```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](https://cloud.openobserve.ai) with a 14-day free trial, and start exploring your own traces and logs.
- Read the [OpenObserve Kubernetes integration docs](https://openobserve.ai/docs/integration/system/k8s/) for advanced installation options.
- Related reading: [Kubernetes monitoring with OpenTelemetry and Prometheus](/blog/kubernetes-monitoring-with-opentelemetry-prometheus/).

## Frequently Asked Questions

### How do I set up distributed tracing on Kubernetes with OpenTelemetry?

Install the OpenTelemetry Operator and deploy a Collector that exports traces to OpenObserve. Grant the Collector read access to the Kubernetes resources needed for attribute enrichment, such as Pods and Namespaces. Create an Instrumentation resource, annotate your workloads, and recreate their Pods. Send a request to verify distributed tracing works across participating services.

### How do I auto-instrument pods with the OpenTelemetry Operator?

Create an Instrumentation resource with your Collector endpoint, then add the language-specific injection annotation, such as instrumentation.opentelemetry.io/inject-java, to each Deployment's Pod template. The Operator injects the agent through an init container when the Pods are recreated.

### When should I run the OpenTelemetry Collector as a DaemonSet, sidecar, or gateway for traces?

Use a DaemonSet when you want node-level metrics alongside traces, a sidecar when a workload needs its own isolated Collector, and a gateway for shared processing, sampling, and export. Many teams combine them in an agent-to-gateway pattern, which is what the OpenObserve Kubernetes installer deploys.

### Why are my traces broken or spans missing on Kubernetes?

Failed instrumentation injection, missing Kubernetes attributes, sampling choices, and Collector health can all cause broken traces or missing spans. Check them in that order and review the Collector logs for receive, processing, and export errors.

### How do I connect traces to logs for the same request on Kubernetes?

Configure your Collector to receive logs over OTLP and enrich them with Kubernetes attributes, just like your traces. The Collector's logs pipeline forwards those logs to OpenObserve with the trace context intact, so you can query logs by trace_id and see every log line for the same request.

### Why can't I find my application logs in OpenObserve?

Verify that a logs pipeline exists in the OpenObserve Gateway Collector and that the Instrumentation resource exports application logs over OTLP. Without both, traces arrive but the application's logs do not.
