Observability Driven Development Guide

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.

Designing for Observability from the Start

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:

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.

Instrumenting Code with Purpose

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.

Validating Observability in CI

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.

Debugging with Correlation

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:

When a service receives a request, it extracts the traceparent and uses it to:

  1. Start a new span in the current service
  2. Inject the traceparent into outgoing HTTP requests
  3. Add the traceparent to all logs via log.WithContext(ctx)

A failing /api/orders endpoint, for example, can be debugged by:

The 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.

On-Call Debugging with the Observability Stack

When an alert fires, the on-call engineer follows a standard workflow:

  1. Check the dashboard: A high error rate alert on the /api/users service shows a spike in latency and 5xx errors.
  1. Drill into the trace: The dashboard links to a distributed trace. The trace shows that the error occurs during user creation, with a slow database call and a missing userId field in the payload.
  1. Examine the logs: The trace ID is used to filter logs. The engineer sees:
    {
      "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.

  1. Query metrics: The engineer uses the trace ID to query metrics:
    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.

  1. Create a fix: The engineer adds a userId field to the frontend request and deploys the change.
  1. Verify: The CI pipeline runs again, and the on-call engineer confirms that the new logs and traces appear with userId set.

Common Pitfalls and Sharp Edges

Evolving Observability with Feedback

ODD is not a one-time setup. Teams evolve observability through feedback loops:

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.