nrgrpc

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2018 License: MIT Imports: 9 Imported by: 0

README

nrgrpc

Build Status codecov GoDoc Go project version Go Report Card license

gRPC stats.Handler implementation to measure and send performances metrics to New Relic.

Example

gRPC server

nrgrpc.NewServerStatsHandler creates a stats.Handler instance for gRPC servers. When the handler is passed to a gRPC server with stats.StatsHandler, it will set a newrelic.Transaction into a request context.Context using newrelic.NewContext. So you can retrieve newrelic.Transaction instances with newrelic.FromContext.

func main() {
	lis, err := net.Listen("tcp", ":3000")
	if err != nil {
		panic(err)
	}

	// Initiailze a `newrelic.Appliation`
	nrapp, err := newrelic.NewApplication(newrelic.Config{
		AppName: "your_app",
		License: "your_license_key",
	})
	if err != nil {
		panic(err)
	}

	s := grpc.NewServer(
		// Create a `stats.Handler` from `newrelic.Application`
		stats.StatsHandler(nrgrpc.NewServerStatsHandler(nrapp)),
	)

	// Register server implementations

	s.Serve(lis)
}
gRPC client
func main() {
	// Initiailze a `newrelic.Appliation`
	nrapp, err := newrelic.NewApplication(newrelic.Config{
		AppName: "your_app",
		License: "your_license_key",
	})
	if err != nil {
		panic(err)
	}

	// Create a `grpc.ClientConn` with `stats.Handler`
	conn, err := grpc.Dial(
		":3000",
		grpc.WithInsecure(),
		grpc.WithStatsHandler(nrgrpc.NewClientStatsHandler()),
	)
	if err != nil {
		panic(err)
	}


	// Register http handler using `https://godoc.org/github.com/newrelic/go-agent.WrapHandleFunc`.
	// This wrapper sets `newrelic.Transaction` into the `http.Request`'s context.
	nrhttp.WrapHandleFunc(app, "/foo", func(w http.ResponseWriter, r *http.Request) {
		resp, err := NewFooServiceClient.BarCall(r.Context(), &BarRequest{})
		// ...
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientStatsHandler added in v0.1.0

func NewClientStatsHandler() stats.Handler

NewClientStatsHandler creates a new stats.Handler instance for measuring application performances with New Relic.

func NewGatewayStatsHandler added in v0.1.0

func NewGatewayStatsHandler() stats.Handler

NewGatewayStatsHandler creates a new stats.Handler instance for measuring application performances with New Relic.

func NewServerStatsHandler added in v0.1.0

func NewServerStatsHandler(app newrelic.Application, opts ...Option) stats.Handler

NewServerStatsHandler creates a new stats.Handler instance for measuring application performances with New Relic.

Types

type Option

type Option func(Options) Options

Option is a function for building configurations object for an interceptor

func WithIgnoredMethods

func WithIgnoredMethods(fullMethods ...string) Option

WithIgnoredMethods receives full method names to get newrelic to ignore them

func WithIgnoredServices

func WithIgnoredServices(services ...string) Option

WithIgnoredServices receives service names to get newrelic to ignore them

type Options

type Options struct {
	IgnoredServices map[string]struct{}
	IgnoredMethods  map[string]struct{}
}

Options contains some configurations for an interceptor

func (*Options) IsIgnored

func (o *Options) IsIgnored(fullMethod string) bool

IsIgnored returned true if the given method is ignored

Directories

Path Synopsis
Package testing is a generated protocol buffer package.
Package testing is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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