Skip to content

Package otgrpc provides OpenTracing support for any gRPC client or server.

License

Notifications You must be signed in to change notification settings

opentracing-contrib/go-grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2f9c7e3 · Jan 22, 2025

History

35 Commits
Jan 22, 2025
Jan 22, 2025
Nov 8, 2024
May 18, 2018
Nov 7, 2024
Feb 24, 2020
Nov 8, 2024
Nov 7, 2024
Nov 7, 2024
Nov 7, 2024
Jan 22, 2025
Jan 22, 2025
Nov 7, 2024
May 18, 2018
Nov 8, 2024
Nov 7, 2024
Nov 7, 2024

Repository files navigation

OpenTracing support for gRPC in Go

CI Go Report Card GitHub go.mod Go version GitHub release (latest SemVer)

The otgrpc package makes it easy to add OpenTracing support to gRPC-based systems in Go.

Installation

go get github.com/opentracing-contrib/go-grpc

Documentation

See the basic usage examples below and the package documentation on godoc.org.

Client-side usage example

Wherever you call grpc.Dial:

// You must have some sort of OpenTracing Tracer instance on hand.
var tracer opentracing.Tracer = ...
...

// Set up a connection to the server peer.
conn, err := grpc.Dial(
    address,
    ... // other options
    grpc.WithUnaryInterceptor(
        otgrpc.OpenTracingClientInterceptor(tracer)),
    grpc.WithStreamInterceptor(
        otgrpc.OpenTracingStreamClientInterceptor(tracer)))

// All future RPC activity involving `conn` will be automatically traced.

Server-side usage example

Wherever you call grpc.NewServer:

// You must have some sort of OpenTracing Tracer instance on hand.
var tracer opentracing.Tracer = ...
...

// Initialize the gRPC server.
s := grpc.NewServer(
    ... // other options
    grpc.UnaryInterceptor(
        otgrpc.OpenTracingServerInterceptor(tracer)),
    grpc.StreamInterceptor(
        otgrpc.OpenTracingStreamServerInterceptor(tracer)))

// All future RPC activity involving `s` will be automatically traced.