Tracing gRPC calls in Golang with Google Stackdriver

Breakdown of request time including time spent within RPC’s.

Google Cloud Platform recently released Stackdriver Trace which helps highlight and debug performance bottlenecks within our software. The library gives us the ability to inspect detailed latency information for each step of a programs execution.

Out of the box Google Cloud Go library includes some really nice plumbing for passing trace context between HTTP requests. However, this is currently not the case when tracing remote procedure calls with gRPC.

Docs from Google Trace library

To associate our remote child processes with their parent spans we’ll need to pass a special trace context header along with the gRPC request.

TRACE_ID/SPAN_ID;o=TRACE_TRUE"

Similar to the Google Cloud trace dial option we can create a new client interceptor that adds the google cloud context header to the gRPC metadata before invoking the request.

When the request lands on the downstream service we can use a server interceptor to parse the trace header from the request metadata and create a new child span of the parent trace.

This gives us the ability to create new child spans within the downstream service that are associated with the parent span from the RPC.

Tracing overview in Stackdriver (Google Cloud Trace).

--

--

--

Nothing ventured, nothing Gained. CTO at @Clearbit. I value learning over being right. Read more at www.hward.com.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Harlow

Harlow

Nothing ventured, nothing Gained. CTO at @Clearbit. I value learning over being right. Read more at www.hward.com.

More from Medium

Host Private Node.JS Packages on the Google Cloud with Artifact Registry

gRPC rocks build your first gRPC service(part 1)

Deep Dive into Google’s AlloyDB Architecture for PostgreSQL

API Key Implementation On ELK Stack