← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Spans & Traces

Observability Beginner
debt(d9/e5/b5/t5)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints note automated=no and the only tool listed is opentelemetry itself (the instrumentation framework, not a linter/analyzer). Missing spans, wrong granularity, or missing ERROR status produce no warnings — traces simply look incomplete or healthy while bottlenecks go undetected until users complain.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix requires adding spans across DB queries, HTTP calls, cache operations, and business steps, plus setting ERROR status on exceptions and adding attributes. This isn't a single-line swap — it requires instrumenting multiple call sites across the codebase, though it doesn't necessarily require architectural rework.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The term applies_to web, cli, and queue-worker contexts, meaning span granularity decisions affect all major execution paths. Poor instrumentation decisions (too coarse or too fine) persistently degrade the value of observability across the codebase and require ongoing maintenance as new features are added.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception is that spans must represent function calls, when they can represent any logical operation. The common_mistakes confirm this: developers default to one span per request or per line of code, and critically miss setting span status=ERROR on exceptions — making traces appear successful when they are not. These are well-documented gotchas that most developers encounter.

About DEBT scoring →

TL;DR

A trace is one request's full journey; spans are the individual operations within it — each span has a name, start time, duration, status, and optional attributes.

Explanation

Trace: collection of spans sharing a trace ID. Root span: first span in a request. Child spans: nested operations (DB query, HTTP call, cache lookup). Span attributes: key-value data (db.statement, http.url, user.id). Span events: timestamped events within a span (cache.miss). Span status: OK, ERROR, UNSET. Span kind: SERVER, CLIENT, PRODUCER, CONSUMER, INTERNAL. W3C Trace Context: traceparent header carries (version, trace-id, parent-id, flags). Sampling: recording every span is expensive — sample 1-10% in production or use head/tail-based sampling.

Common Misconception

Spans must represent function calls — a span can represent any operation: a DB query, an HTTP call, a business step ('checkout'), or an external API call.

Why It Matters

Understanding span granularity determines how useful traces are — too coarse misses bottlenecks; too fine creates noise and cost.

Common Mistakes

  • One span per request — no internal visibility.
  • Span per line of code — noise and cost.
  • Missing DB spans — usually the most important.
  • Not setting span status=ERROR on exception — traces look successful.

Code Examples

✗ Vulnerable
// Single span for entire request — no internal visibility:
$span = $tracer->spanBuilder('handleRequest')->startSpan();
try { handleRequest(); } finally { $span->end(); }
✓ Fixed
// Nested spans:
$requestSpan = $tracer->spanBuilder('POST /orders')->setSpanKind(SpanKind::SERVER)->startSpan();
$dbSpan = $tracer->spanBuilder('SELECT orders')->setSpanKind(SpanKind::CLIENT)->startSpan();
$dbSpan->setAttribute('db.statement', 'SELECT * FROM orders WHERE id = ?');
try { $result = $pdo->query(...); }
catch (Exception $e) { $dbSpan->setStatus(StatusCode::ERROR, $e->getMessage()); throw $e; }
finally { $dbSpan->end(); }

Added 23 Mar 2026
Views 52
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 2 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 3 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Perplexity 8 Google 4 Ahrefs 4 SEMrush 4 ChatGPT 3 Scrapy 3 Claude 2 Unknown AI 1 Meta AI 1
crawler 35 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Add spans for: DB queries, HTTP calls, cache operations, and key business steps. Set ERROR status on exceptions. Add relevant attributes (IDs, URLs, query). Sample in production.
📦 Applies To
web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
spanBuilder|startSpan
Auto-detectable: ✗ No opentelemetry
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: Function


✓ schema.org compliant