Provision OpenTelemetry trace lab dashboard
Homelab Main / validate (push) Successful in 1m12s Details
Homelab Main / running-update (push) Successful in 3s Details
Homelab Main / debian-ops (push) Successful in 3s Details

This commit is contained in:
juvenal.diaz 2026-11-09 22:18:27 -06:00
parent d6980575f9
commit f12bcc34c0
4 changed files with 120 additions and 7 deletions

View File

@ -39,10 +39,11 @@ kubectl --kubeconfig="$HOME/.kube/opi5-k3s-config" -n monitoring \
get cronjob otel-lab-demo
```
The job runs every five minutes. In Grafana, open **Explore → Tempo Lab →
Search**, choose `jeannie-demo-frontend` as the service and run the query. Open
a trace to inspect its child span. The datasource relies on the Grafana
datasource sidecar enabled by the platform chart. For immediate testing, create
The job runs every five minutes. Open the provisioned **OpenTelemetry Trace
Lab** dashboard at `https://grafana.lab2025.duckdns.org/d/otel-lab` to see
recent synthetic traces automatically. Select a table row to display its
parent and child in the timeline. The dashboard and datasource rely on the
Grafana sidecars enabled by the platform chart. For immediate testing, create
one job and inspect its trace ID:
```bash
@ -52,9 +53,9 @@ kubectl --kubeconfig="$HOME/.kube/opi5-k3s-config" -n monitoring \
logs job/otel-lab-demo-manual
```
The printed trace ID can be pasted into Grafana's Tempo trace-ID query. A
successful generator job confirms the collector accepted the request; check
Tempo and Grafana as well to establish end-to-end visibility. Manual job names
The printed trace ID can also be entered in the dashboard's **Selected trace**
field. A successful generator job confirms the collector accepted the request;
check the dashboard as well to establish end-to-end visibility. Manual job names
must be unique, or wait for Kubernetes' job TTL to remove the previous one.
ConfigMaps are mounted as files; restart the relevant deployment after changing
its configuration because these binaries do not automatically reload it.

View File

@ -5,6 +5,13 @@ configMapGenerator:
namespace: monitoring
files:
- trace_demo.py
- name: otel-lab-dashboard
namespace: monitoring
files:
- otel-lab-dashboard.json
options:
labels:
grafana_dashboard: "1"
generatorOptions:
disableNameSuffixHash: true
resources:

View File

@ -0,0 +1,91 @@
{
"annotations": {"list": []},
"description": "Explore the OpenTelemetry learning pipeline and its synthetic parent/child traces.",
"editable": false,
"id": null,
"uid": "otel-lab",
"title": "OpenTelemetry Trace Lab",
"tags": ["homelab", "opentelemetry", "tempo"],
"timezone": "browser",
"schemaVersion": 39,
"version": 1,
"refresh": "1m",
"time": {"from": "now-6h", "to": "now"},
"templating": {
"list": [
{
"name": "traceId",
"label": "Selected trace",
"type": "textbox",
"query": "",
"current": {"text": "", "value": ""},
"hide": 0
}
]
},
"panels": [
{
"id": 1,
"type": "text",
"title": "Trace pipeline",
"gridPos": {"h": 4, "w": 24, "x": 0, "y": 0},
"options": {
"mode": "markdown",
"content": "Synthetic demo → OpenTelemetry Collector → Tempo → Grafana. The job emits a synthetic parent and child every five minutes. Select a row in the table to open its trace below. Tempo data is temporary and is lost when its pod is replaced."
}
},
{
"id": 2,
"type": "stat",
"title": "Collector ready replicas",
"gridPos": {"h": 4, "w": 8, "x": 0, "y": 4},
"datasource": {"type": "prometheus", "uid": "prometheus"},
"targets": [{"refId": "A", "expr": "kube_deployment_status_replicas_available{namespace=\"monitoring\",deployment=\"otel-lab-collector\"}", "instant": true}],
"options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}}
},
{
"id": 3,
"type": "stat",
"title": "Tempo ready replicas",
"gridPos": {"h": 4, "w": 8, "x": 8, "y": 4},
"datasource": {"type": "prometheus", "uid": "prometheus"},
"targets": [{"refId": "A", "expr": "kube_deployment_status_replicas_available{namespace=\"monitoring\",deployment=\"otel-lab-tempo\"}", "instant": true}],
"options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}}
},
{
"id": 4,
"type": "stat",
"title": "Demo job suspended",
"description": "Zero means the five-minute synthetic trace schedule is enabled.",
"gridPos": {"h": 4, "w": 8, "x": 16, "y": 4},
"datasource": {"type": "prometheus", "uid": "prometheus"},
"targets": [{"refId": "A", "expr": "kube_cronjob_spec_suspend{namespace=\"monitoring\",cronjob=\"otel-lab-demo\"}", "instant": true}],
"options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}}
},
{
"id": 5,
"type": "table",
"title": "Recent synthetic traces",
"description": "TraceQL finds the synthetic frontend spans. Select a result to load its complete trace in the panel below.",
"gridPos": {"h": 10, "w": 24, "x": 0, "y": 8},
"datasource": {"type": "tempo", "uid": "tempo-lab"},
"targets": [{"refId": "A", "queryType": "traceql", "query": "{ resource.service.name = \"jeannie-demo-frontend\" }", "limit": 50, "tableType": "traces"}],
"fieldConfig": {
"defaults": {
"links": [{"title": "Show trace on this dashboard", "url": "/d/otel-lab/opentelemetry-trace-lab?var-traceId=${__data.fields.traceID}&${__url_time_range}", "targetBlank": false}]
},
"overrides": []
},
"options": {"showHeader": true}
},
{
"id": 6,
"type": "traces",
"title": "Selected trace timeline",
"description": "Choose a trace in the table. The parent and child represent synthetic services, not live application calls.",
"gridPos": {"h": 14, "w": 24, "x": 0, "y": 18},
"datasource": {"type": "tempo", "uid": "tempo-lab"},
"targets": [{"refId": "A", "queryType": "traceql", "query": "${traceId}"}]
}
]
}

View File

@ -1,4 +1,5 @@
import importlib.util
import json
from pathlib import Path
import unittest
@ -12,6 +13,19 @@ spec.loader.exec_module(demo)
class OpenTelemetryLabTest(unittest.TestCase):
def test_dashboard_is_provisioned_and_targets_the_lab(self):
manifest = yaml.safe_load((LAB / 'kustomization.yaml').read_text())
generator = next(item for item in manifest['configMapGenerator'] if item['name'] == 'otel-lab-dashboard')
self.assertEqual(generator['options']['labels']['grafana_dashboard'], '1')
dashboard = json.loads((LAB / 'otel-lab-dashboard.json').read_text())
self.assertEqual(dashboard['uid'], 'otel-lab')
table = next(panel for panel in dashboard['panels'] if panel['id'] == 5)
trace = next(panel for panel in dashboard['panels'] if panel['id'] == 6)
self.assertEqual(table['datasource']['uid'], 'tempo-lab')
self.assertIn('jeannie-demo-frontend', table['targets'][0]['query'])
self.assertIn('var-traceId=${__data.fields.traceID}', table['fieldConfig']['defaults']['links'][0]['url'])
self.assertEqual(trace['targets'][0]['query'], '${traceId}')
def test_synthetic_trace_has_connected_parent_and_child(self):
trace_id, parent_id, child_id = 'a' * 32, 'b' * 16, 'c' * 16
trace = demo.build_trace(1_000_000_000, trace_id, parent_id, child_id)