ogrpc

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2020 License: ISC Imports: 18 Imported by: 2

README

Go Doc

ogrpc

This package can be used for making gRPC servers and clients observable. It uses interceptors to intercept your gRPC methods and provides logs, metrics, and traces out-of-the-box.

Quick Start

Here is a snippet of what you need to do on server-side:

obsv := observer.New(true,
  observer.WithMetadata("server", "", "", "", nil),
  observer.WithLogger("info"),
)
defer obsv.End(context.Background())

si := ogrpc.NewServerInterceptor(obsv, ogrpc.Options{})
opts := si.ServerOptions()
server := grpc.NewServer(opts...)
zonePB.RegisterZoneManagerServer(server, &ZoneServer{})

And a snippet of what you need to do on client-side:

obsv := observer.New(true,
  observer.WithMetadata("client", "", "", "", nil),
  observer.WithLogger("info"),
)
defer obsv.End(context.Background())

ci := ogrpc.NewClientInterceptor(obsv, ogrpc.Options{})
opts := ci.DialOptions()
conn, _ := grpc.Dial(grpcServer, opts...)
defer conn.Close()
client := zonePB.NewZoneManagerClient(conn)

You can find the full example here.

Documentation

Overview

Package ogrpc is an observable grpc package. It can be used for building gRPC servers and clients that automatically report logs, metrics, and traces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerStreamWithContext

func ServerStreamWithContext(ctx context.Context, s grpc.ServerStream) grpc.ServerStream

ServerStreamWithContext returns a new grpc.ServerStream with a new context.

Types

type ClientInterceptor

type ClientInterceptor struct {
	// contains filtered or unexported fields
}

ClientInterceptor creates interceptors with logging, metrics, and tracing for grpc clients.

func NewClientInterceptor

func NewClientInterceptor(observer observer.Observer, opts Options) *ClientInterceptor

NewClientInterceptor creates a new server interceptor for observability.

func (*ClientInterceptor) DialOptions

func (i *ClientInterceptor) DialOptions() []grpc.DialOption

DialOptions return grpc dial options for unary and stream interceptors. This can be used for making gRPC method calls observable via logging, metrics, tracing, etc.

type Options

type Options struct {
	LogInDebugLevel bool
	ExcludedMethods []string
}

Options are optional configurations for creating interceptors.

type ServerInterceptor

type ServerInterceptor struct {
	// contains filtered or unexported fields
}

ServerInterceptor creates interceptors with logging, metrics, and tracing for grpc servers.

func NewServerInterceptor

func NewServerInterceptor(observer observer.Observer, opts Options) *ServerInterceptor

NewServerInterceptor creates a new server interceptor for observability.

func (*ServerInterceptor) ServerOptions

func (i *ServerInterceptor) ServerOptions() []grpc.ServerOption

ServerOptions return grpc server options for unary and stream interceptors. This can be used for making gRPC method handlers observable via logging, metrics, tracing, etc. It also observes and recovers panics that happened inside the method handlers.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL