gRPC in Go

Use the instructions below to instrument gRPC in your Go service.

Now that your Go tracer provider is all set, you may instrument your gRPC client and server to get end-to-end visibility and troubleshooting capabilities in Helios.

Package google.golang.org/grpc

In order to instrument and track gRPC requests received by your google.golang.org/grpc implemented server or client, add an interceptor to your client and server definitions.

First, install the OpenTelemetry instrumentation package:

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

Use the following snippet to apply the instrumentation:

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

// server side
grpcServer := grpc.NewServer(
        grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()),
        grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor()),)

// client side
conn, err := grpc.Dial("<destinationAddress>", grpc.WithTransportCredentials(insecure.NewCredentials()),
        grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
        grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),)

// for example:
conn, err := grpc.Dial("localhost:3030", grpc.WithTransportCredentials(insecure.NewCredentials()),
        grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()),
        grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()),)

πŸ‘

All set

After setup is complete and once the service is up and running, it will show up in the Helios application.


Did this page help you?