awesome-everything RU
↑ Back to the climb

Observability

Auto-instrumentation and manual spans: the 80/20 of OTel

Crux Auto-instrumentation covers 70-80% of production traffic for free — HTTP, DB, queues. The remaining 20-30% is manual spans with business attributes, and that is where the real diagnostic value lives.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 11 min

Auto-instrumentation tells you “this HTTP request took 800 ms and made 5 DB queries.” Manual instrumentation tells you “the slow part was the fraud-check loop, which fanned out to 12 calls on the rules engine, of which 3 timed out.” Both are necessary. Neither alone is enough.

Auto-instrumentation: the 70-80% you get for free

Most production traffic flows through a small set of frameworks — HTTP servers, HTTP clients, database drivers, message queue clients — that OTel’s contrib libraries instrument out of the box.

Java: The OTel Java Agent (-javaagent JAR) rewrites bytecode at JVM startup and instruments ~200 libraries automatically — no code changes required. Add one -javaagent flag to the JVM arguments, set OTEL_SERVICE_NAME and OTEL_EXPORTER_OTLP_ENDPOINT env vars, and every HTTP request, JDBC query, and Kafka message is traced.

Python: opentelemetry-instrument wraps the process and monkey-patches common libraries (Flask, Django, FastAPI, SQLAlchemy, Redis, Celery, etc.).

Node.js: @opentelemetry/sdk-node plus a set of instrumentations (express, http, pg, redis, kafkajs) registered before any other require hook framework methods automatically.

Go: Auto-instrumentation is less mature because Go has no monkey-patching. eBPF-based auto-instrumentation (using uprobes) is the emerging approach; the Go OTel contrib libraries require explicit middleware setup per framework.

LanguageAuto-instrumentation mechanismCoverage
Java-javaagent JAR, bytecode rewriting at startup~200 libraries, HTTP + DB + queues + caches
Pythonopentelemetry-instrument, monkey-patchingFlask, Django, FastAPI, SQLAlchemy, Redis, Celery
Node.jsrequire hook before other importsexpress, http, pg, redis, kafkajs, grpc
GoMiddleware setup per framework (no monkey-patching)net/http, gRPC, database/sql — requires manual wiring

The 70-80% is the easy part: HTTP routes, DB queries, cache calls, queue interactions. Auto-instrumentation tells you what happened. Manual instrumentation tells you why.

Manual instrumentation: the value bridge

The remaining 20-30% — business-specific spans, custom attributes, and cross-cutting concerns — is where the real diagnostic value lives, because it is where the business questions live.

Pattern: open a span around a business operation, attach attributes that describe the operation, emit span events for noteworthy moments.

const span = tracer.startSpan("fraud.check", {
  attributes: {
    "customer.segment": customer.segment,
    "order.value_cents": order.valueCents,
    "feature_flag.fraud_model": flags.fraudModel,
  },
});

try {
  for (const rule of rules) {
    const result = await rules.engine.evaluate(rule, order);
    span.addEvent("rule.evaluated", {
      "rule.id": rule.id,
      "rule.result": result.outcome,
      "rule.latency_ms": result.latencyMs,
    });
  }
} catch (err) {
  span.recordException(err);
  span.setStatus({ code: SpanStatusCode.ERROR });
} finally {
  span.end();
}

This span tells you customer segment, order value, the feature flag state of the fraud model, and the result of every rule evaluation — data that auto-instrumentation cannot see because it does not know your business domain.

The platform wrapper pattern

Manual instrumentation is the same pattern in every service, so platform teams publish a thin helper library that wraps the OTel API with org-specific conventions:

  • Typed business attributes — pre-defined attribute names for common concepts (customer segment, feature flag state, batch size) so teams cannot misspell them.
  • Redaction helpers — strip PII before attaching to spans (email → hash, SSN → masked).
  • Span event helpers — typed helpers for common events (cache miss, retry, fallback).
  • Resource pre-configuration — service name, version, and deployment environment from a standardised env var set.

New services import the wrapper; CI lint rejects raw OTel SDK usage in new code (to prevent ungoverned attribute naming). Override hooks let teams add service-specific attributes without modifying the wrapper.

Why this works

Why not one span per function? Every span has overhead: the SDK allocates the span struct, records attributes, runs the sampler, and when the span ends, runs the batch processor, serializes to OTLP, and possibly queues for the exporter. At ~1-5 μs per span, 100 spans per request at 10k RPS is 1-5 ms of CPU overhead per core per second. More importantly, a flat list of 100 function-level spans is harder to read than 8 spans at the right abstraction level. The guideline: one span per service-boundary crossing plus one per significant subsystem call (one span for the fraud check, one for the DB query inside it, not one span per method inside the fraud check).

Quiz

What does auto-instrumentation cover that manual instrumentation cannot, and what does manual instrumentation cover that auto-instrumentation cannot?

Quiz

Why does a platform team publish a per-language wrapper around the OTel SDK instead of letting application teams call the OTel SDK directly?

Order the steps

Order the steps to add a well-instrumented business span to a service:

  1. 1 Open a span with a descriptive operation name (e.g., fraud.check)
  2. 2 Attach structured attributes: customer segment, order value, feature flag state
  3. 3 Execute the business logic
  4. 4 Emit span events for significant moments: cache miss, retry, rule evaluation result
  5. 5 On error: call span.recordException(err) and set status to ERROR
  6. 6 Always call span.end() in a finally block to ensure the span is flushed
Recall before you leave
  1. 01
    Why is the OTel Java Agent the most powerful auto-instrumentation option across languages?
  2. 02
    What is the right granularity for manual spans, and why?
  3. 03
    What does the platform wrapper pattern solve, and what does it cost?
Recap

Auto-instrumentation instruments 70-80% of production traffic for free: the OTel Java Agent rewrites bytecode to cover ~200 libraries; Python’s opentelemetry-instrument monkey-patches common frameworks; Node.js uses a require-hook before other imports. Go requires manual middleware setup (no monkey-patching). The remaining 20-30% is manual spans: open a span around a business operation, attach typed attributes (customer segment, feature flag state, batch size), emit span events for noteworthy moments, record exceptions with span.recordException(). The overhead is ~1-5 μs per span — keep granularity at the business-operation level, not the function level. Platform teams publish a per-language wrapper that enforces Semantic Conventions, redaction, and resource configuration, so application teams can add business spans without inventing new attribute names.

Connected lessons
appears again in167
Continue the climb ↑The OTel Collector: receivers, processors, exporters, and deployment patterns
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.