gRPC Observability and Tracing

Observability means understanding what happens inside a running system by looking at its outputs. A single user action may cross a dozen gRPC services. When the action runs slowly or fails, teams need evidence that shows where and why. Logs, metrics, and traces supply that evidence.

The Hospital Monitor Analogy

A hospital monitors patients with several instruments. A thermometer gives one number. A heart monitor draws a continuous line. A medical chart records events over time. No single instrument tells the whole story. Observability uses three signals in the same way.

SignalQuestion It AnswersExample
LogsWhat happened?"Payment declined for order 8841"
MetricsHow much and how often?250 calls per second, 1.2 percent errors
TracesWhere did the time go?Database call took 400 ms of 520 ms

Key Metrics to Track

The RED method gives a short list that covers most needs for request based services.

  • Rate: calls per second for each method
  • Errors: calls that return a failing status code, grouped by code
  • Duration: latency percentiles such as p50, p95, and p99

Track percentiles, not averages. An average of 100 milliseconds can hide a slow tail where one call in a hundred takes five seconds.

What a Trace Looks Like

A trace follows one request across every service. Each unit of work becomes a span with a start time and a duration. Spans nest to show who called whom.

Trace 7f3a...  total 520 ms

Gateway.PlaceOrder      ├──────────────────────────────────┤ 520 ms
  Order.Create            ├───────────────────────────┤ 470 ms
    Stock.Reserve           ├────┤ 60 ms
    Payment.Charge                ├──────────────┤ 380 ms
      Bank.Authorize                ├───────────┤ 350 ms

The picture reveals the slow step immediately: the bank authorization consumes most of the time.

How Trace Context Travels

Each service must know which trace it joins. The caller sends a trace identifier in gRPC metadata, usually in the W3C traceparent header. The receiving service reads the header, creates a child span, and passes the identifier onward. Instrumentation libraries handle this exchange automatically.

Service A ──metadata: traceparent=00-7f3a...-01──▶ Service B
Service B ──metadata: traceparent=00-7f3a...-02──▶ Service C
Same trace ID, new span ID at every hop

Add OpenTelemetry in Go

OpenTelemetry offers a vendor neutral standard for traces and metrics. A stats handler plugs into the server and client with one line each.

import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"

server := grpc.NewServer(
  grpc.StatsHandler(otelgrpc.NewServerHandler()),
)

conn, err := grpc.NewClient(addr,
  grpc.WithTransportCredentials(creds),
  grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
)

Spans and standard RPC metrics now flow to the configured exporter. Common destinations include Jaeger, Tempo, Prometheus, and commercial platforms.

Structured Logs with Request IDs

Write logs as key and value pairs, not free text. Include the trace ID in every line. Engineers then jump from a failing trace to the matching log lines in one search.

{"level":"error","method":"/shop.PaymentService/Charge","code":"UNAVAILABLE",
 "trace_id":"7f3a...","duration_ms":380}

Build Useful Dashboards

Start with one dashboard per service. Show request rate, error rate, and latency percentiles by method. Add saturation signals such as CPU, memory, and open connections. A clear dashboard lets an on call engineer judge system health in seconds.

Alert on Symptoms

Alerts should describe user impact: error rate above one percent for five minutes, or p99 latency above one second. Avoid alerts on every small internal fluctuation. Noisy alerts train people to ignore pages.

Sampling

Recording every trace costs storage and money at high traffic. Sampling keeps a fraction, such as one trace in a hundred. Tail based sampling keeps all slow or failing traces and drops healthy ones, which preserves the most valuable evidence.

Summary

Combine logs, metrics, and traces to see inside gRPC systems. Track rate, errors, and duration. Propagate trace context through metadata, adopt OpenTelemetry, log with trace IDs, and alert on user facing symptoms. Good visibility turns hours of guessing into minutes of diagnosis.