liveBook · Manning

Interceptor

As explained in gRPC Microservices in Go

A gRPC interceptor is middleware that runs around gRPC calls on the client or server to inspect, modify, or instrument them.

A gRPC interceptor centralizes cross-cutting behavior around client or server calls, avoiding duplicated instrumentation and resilience logic across services. section 9.2.2 section 9.3.5

Use interceptors to:

  • Collect gRPC metrics and telemetry from client calls, such as Order calling Payment. section 9.2.2
  • Attach server-side tracing and metrics to every request reaching a gRPC service. section 9.3.5
  • Handle retry operations centrally when building resilient systems. section 9.2.2

Instrumenting an Order-to-Payment call

Add otelgrpc.UnaryClientInterceptor() to the client's grpc.Dial options so requests from Order to Payment produce telemetry. On the Order server, add otelgrpc.UnaryServerInterceptor() to grpc.NewServer. Configure a tracing provider with a Jaeger exporter, batch collection, service metadata, and trace propagation so the complete cross-service flow appears in Jaeger. section 9.2.2 section 9.3.5

...
var opts []grpc.DialOption
    opts = append(opts,
        grpc.WithTransportCredentials(insecure.NewCredentials()),
        grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),   #1
    )
    conn, err := grpc.Dial(paymentServiceUrl, opts...)
...

Shows the client-side grpc.Dial configuration that installs an OpenTelemetry unary interceptor. section 9.2.2

import (
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
)
...
grpcServer := grpc.NewServer(
        grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()),
    )
...

Shows the server-side grpc.NewServer configuration that installs an OpenTelemetry unary interceptor. section 9.3.5

How gRPC Microservices in Go covers it

How deep it goes
Explains client and server installation, tracing-provider configuration, batching, metadata, and propagation without detailing interceptor internals.
Examples
Uses Order-to-Payment calls, unary client and server interceptors, Jaeger export, and Jaeger UI trace inspection.
What it assumes
Assumes Go gRPC service setup and introduces the required OpenTelemetry, Jaeger exporter, and collector configuration.
What you can do after
Configure gRPC client and server interceptors to collect, propagate, batch, and export service telemetry.
How it connects
Connects gRPC calls with observability, metrics, tracing, retry operations, trace propagation, Jaeger, and OpenTelemetry.

Also explained in

Compare how 2 books explain interceptor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.