Course contentsShow
← System Design
Lesson 1223 of 1,91931. Observability: TracingFree lesson

Instrumentation Basics

The process of adding tracing code to applications to create and propagate spans at service entry and exit points.

Instrumentation Basics

What you'll learn: How to add tracing code to your applications so they can create and propagate span information across distributed service calls.

What is Instrumentation?

Instrumentation is the process of modifying your application code to emit trace data—specifically creating spans at important boundaries and propagating trace context between services. Without instrumentation, your services can't participate in distributed tracing, no matter how sophisticated your tracing backend is.

Think of it like installing GPS trackers at every checkpoint along a delivery route. Each service needs to "check in" by creating a span when it starts work, and "check out" when it finishes, passing along the tracking information to the next service in the chain.

Key Instrumentation Points

The most critical places to instrument are:

Service entry points: When a request arrives (HTTP endpoint, message consumer, RPC handler), create a new span or continue an existing trace using the incoming trace ID and span ID.

Service exit points: When making outgoing calls (HTTP clients, message producers, database calls), create a child span and inject the trace context into the outbound request headers.

Between these boundaries, you may also instrument internal operations, but entry/exit points are essential for connecting traces across service boundaries.

The Instrumentation Flow

  1. Extract trace context from incoming requests (Trace ID, Span ID)
  2. Create a new span for this service's work
  3. Inject trace context into outgoing requests
  4. Complete the span when work finishes, recording duration and metadata

This extract-create-inject pattern ensures spans form proper parent-child relationships and traces flow continuously across your distributed system.

Key Takeaway: Instrumentation means adding code at service boundaries to create spans and propagate trace context, enabling end-to-end request tracking across distributed systems.