https://github.com/charithe/otgrpc
Opentracing instrumentation for gRPC
https://github.com/charithe/otgrpc
go golang grpc opentracing
Last synced: about 2 months ago
JSON representation
Opentracing instrumentation for gRPC
- Host: GitHub
- URL: https://github.com/charithe/otgrpc
- Owner: charithe
- License: apache-2.0
- Created: 2017-03-19T18:53:22.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T18:12:50.000Z (almost 9 years ago)
- Last Synced: 2024-06-20T06:33:09.177Z (almost 2 years ago)
- Topics: go, golang, grpc, opentracing
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 9
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Go gRPC Opentracing Instrumentation
===================================
[](https://godoc.org/github.com/charithe/otgrpc)
An attempt to use [Opentracing](http://opentracing.io/) with [gRPC](http://grpc.io) services. The official
[grpc-opentracing](https://github.com/grpc-ecosystem/grpc-opentracing) library currently only supports tracing
unary calls. This library makes use of gRPC `stats.Handler` interface to add tracing to gRPC streams as well.
The obvious approach to add tracing would be to make use of gRPC interceptors. However, the current interceptor
interfaces lack the fuctionality to effectively add tracing information to the calls. Go gRPC has a built-in tracing
mechanism that hooks into `x/net/trace`, but, the captured data is not accessible from external code. This leads us to
the `stats.Handler` interface which is primarily designed for stats gathering but, in the process, gives us access to
all interesting events that happen during a RPC -- which can be used to gather the tracing information we need.
Usage
-----
Grab the library:
```
go get github.com/charithe/otgrpc
```
Client side:
```go
tracer := // Tracer implementation
th := otgrpc.NewTraceHandler(tracer)
conn, err := grpc.Dial(address, grpc.WithStatsHandler(th))
...
```
Server side:
```go
tracer := // Tracer implementation
th := otgrpc.NewTraceHandler(tracer)
server := grpc.NewServer(grpc.StatsHandler(th))
...
```
### Options
Limit tracing to methods of your choosing
```go
tf := func(method string) bool {
return method == "/my.svc/my.method"
}
th := otgrpc.NewTraceHandler(tracer, orgrpc.WithTraceEnabledFunc(tf))
```
Attach payloads as Span log events
```go
th := otgrpc.NewTraceHandler(tracer, otgrpc.WithPayloadLogging())
```