Production-grade guide to observability driven development guide covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Observability Driven Development (ODD) is a development practice where engineering teams use real-time, contextual data from their systems to guide the design, implementation, testing, and evolution of software. It matters most when teams are building or maintaining distributed systems where failure modes are subtle, latency is critical, and debugging requires stitching together logs, metrics, and traces across services. ODD transforms observability from a post-deployment monitoring activity into a core part of the software lifecycle.
Observability is not an afterthought. It begins in the design phase, where developers define what “success” looks like beyond the expected response code. A service is not “working” if it returns HTTP 200; it is working only when the end-to-end latency is under 300ms, error rate is below 1%, and the downstream dependencies are healthy. To achieve this, teams define observability signals early using a shared vocabulary.
The foundation is the observability contract—a document or configuration that specifies:
requests.total, latency.p95, error.rate)event: user.created, context: { userId, sessionId })span.kind: client, span.name: payment.process)These are not just requirements but code artifacts. For example, a observability.yaml file in the project root defines how services should report data:
observability:
metrics:
- name: requests.total
type: counter
help: "Total number of incoming requests"
labels: [method, path, status]
- name: latency.p95
type: histogram
help: "95th percentile of request latency"
buckets: [10, 50, 100, 250, 500, 1000]
logs:
- level: info
message: "User created"
fields:
- name: userId
type: string
- name: source
type: string
default: "api"
traces:
- name: payment.process
kind: server
attributes:
- name: payment.id
type: string
- name: currency
type: string
required: true
This file is checked into version control and used by CI pipelines to validate that services emit the correct data.
Code instrumentation is not just adding log.info() calls. It is the deliberate act of embedding context and signal into every layer of the system.
In a Go service, a handler for /api/users might emit structured logs and trace spans:
func CreateUserHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
trace := otel.Tracer("userservice")
// Start a trace span
ctx, span := trace.Start(ctx, "user.create")
defer span.End()
var user User
if err := json.NewDecoder(r.Body).Decode(&user); err != nil {
span.RecordError(err)
http.Error(w, "invalid request body", http.StatusBadRequest)
return
}
// Add context to the span
span.SetAttributes(
attribute.String("user.email", user.Email),
attribute.String("user.role", user.Role),
attribute.Int("user.age", user.Age),
)
// Log with structured fields
log.WithContext(ctx).Info("Processing user creation", map[string]interface{}{
"event": "user.created",
"userId": user.ID,
"source": "api",
"duration": time.Since(span.StartTime()),
})
// Record metrics
metrics.RequestsTotal.WithLabelValues("POST", "/api/users", "200").Inc()
metrics.LatencyP95.Observe(time.Since(span.StartTime()).Seconds())
// Save user
if err := db.SaveUser(ctx, user); err != nil {
span.RecordError(err)
metrics.ErrorsTotal.WithLabelValues("database", "save_user").Inc()
http.Error(w, "failed to save user", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(map[string]string{"id": user.ID})
}
Each log.WithContext(ctx) call ensures that all logs from this handler are linked to the trace, and the attribute and metric calls produce data that can be visualized and alerted on.
A service is only observability-ready when its signals are validated in CI. The pipeline runs checks that verify both the *presence* and *quality* of observability data.
A CI step checks that every service emits the expected metrics:
- name: Validate metrics
run: |
# Start a mock OpenTelemetry collector
docker run -d --name otel-collector \
-v $(pwd)/observability.yaml:/etc/otel-collector.yaml \
-p 4317:4317 \
otel/opentelemetry-collector:latest \
--config /etc/otel-collector.yaml
# Run the service and wait for metrics
docker-compose up -d --build
sleep 10
# Query Prometheus for expected metrics
curl -s http://localhost:9090/api/v1/query \
-d 'match[]={__name__="requests.total"}' \
| jq '.data.result[0].metric | select(.method == "POST" and .path == "/api/users")'
The CI step fails if the service does not emit requests.total{method="POST", path="/api/users"} within 10 seconds. It also validates logs:
- name: Validate logs
run: |
docker exec -i otel-collector \
tail -f /var/log/otel-collector.log | grep -q "event: user.created"
if [ $? -ne 0 ]; then
echo "Error: Expected log event 'user.created' not found"
exit 1
fi
Logs are validated by checking that a specific event appears with the correct context. If userId is missing, the pipeline fails.
When a service fails in production, the first task is to correlate logs, metrics, and traces. ODD enables this through distributed context propagation using standardized headers.
Each request carries a traceparent header:
traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01
This header is generated by OpenTelemetry and propagated across service boundaries. The traceparent contains:
trace-id: a 16-byte UUID identifying the overall tracespan-id: a 8-byte ID for the current spantrace-flags: a bitmask indicating sampling behaviorWhen a service receives a request, it extracts the traceparent and uses it to:
traceparent into outgoing HTTP requeststraceparent to all logs via log.WithContext(ctx)A failing /api/orders endpoint, for example, can be debugged by:
trace.id to see all activity across servicesThe key insight: every log line, every metric point, every trace span is linked by a single trace ID. A single failure can be explored across systems without manual correlation.
When an alert fires, the on-call engineer follows a standard workflow:
/api/users service shows a spike in latency and 5xx errors.userId field in the payload. {
"timestamp": "2024-01-15T12:34:56Z",
"level": "error",
"message": "Failed to create user",
"event": "user.created",
"trace.id": "0af7651916cd43dd8448eb211c80319c",
"userId": null,
"source": "api",
"error": "json: cannot unmarshal object into Go struct"
}
The userId is null, indicating the frontend sent {"email": "[email protected]"} but not userId.
curl -s 'http://prometheus:9090/api/v1/query?query=latency.p95{service="userservice",span.name="user.create"}' \
| jq '.data.result[0].value'
This returns 1.2s, confirming that the 1.2-second delay is the root cause.
userId field to the frontend request and deploys the change.userId set.traceparent header is not properly propagated. A service might start a new trace instead of continuing the parent one.labels are missing or mismatched. A metric requests.total{method="POST", path="/api/users"} fails to appear because the path label is "/api/users" in one service but "/api/users/" in another.info logs contain event, debug logs do not. The event field is crucial for filtering, but only info and error logs include it.payment.process could mean the entire flow or just the API call. Teams must agree on a naming convention and enforce it.metric objects.log.WithContext(ctx) call is missed, so context is lost. The context field is not included in the log entry, making correlation difficult.user.status is added to observability.yaml, but the service is not updated to emit it. The CI validation fails silently because the metric user.status is not found, but the pipeline does not check the metric’s presence.ODD is not a one-time setup. Teams evolve observability through feedback loops:
event and context?These checks are part of the CI pipeline, ensuring that the system remains observable as it grows.
Observability Driven Development is the practice of building systems that are not only correct but *visible*. Every change, every failure, every deployment is guided by the data that the system produces about itself.
This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy