github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrgrpc/nrgrpc_doc.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 // Package nrgrpc instruments https://github.com/grpc/grpc-go. 5 // 6 // This package can be used to instrument gRPC servers and gRPC clients. 7 // 8 // To instrument a gRPC server, use UnaryServerInterceptor and 9 // StreamServerInterceptor with your newrelic.Application to create server 10 // interceptors to pass to grpc.NewServer. Example: 11 // 12 // 13 // cfg := newrelic.NewConfig("gRPC Server", os.Getenv("NEW_RELIC_LICENSE_KEY")) 14 // app, _ := newrelic.NewApplication(cfg) 15 // server := grpc.NewServer( 16 // grpc.UnaryInterceptor(nrgrpc.UnaryServerInterceptor(app)), 17 // grpc.StreamInterceptor(nrgrpc.StreamServerInterceptor(app)), 18 // ) 19 // 20 // These interceptors create transactions for inbound calls. The transaction is 21 // added to the call context and can be accessed in your method handlers 22 // using newrelic.FromContext. 23 // 24 // Full server example: 25 // https://github.com/newrelic/go-agent/blob/master/_integrations/nrgrpc/example/server/server.go 26 // 27 // To instrument a gRPC client, follow these two steps: 28 // 29 // 1. Use UnaryClientInterceptor and StreamClientInterceptor when creating a 30 // grpc.ClientConn. Example: 31 // 32 // conn, err := grpc.Dial( 33 // "localhost:8080", 34 // grpc.WithUnaryInterceptor(nrgrpc.UnaryClientInterceptor), 35 // grpc.WithStreamInterceptor(nrgrpc.StreamClientInterceptor), 36 // ) 37 // 38 // 2. Ensure that calls made with this grpc.ClientConn are done with a context 39 // which contains a newrelic.Transaction. 40 // 41 // Full client example: 42 // https://github.com/newrelic/go-agent/blob/master/_integrations/nrgrpc/example/client/client.go 43 package nrgrpc 44 45 import "github.com/newrelic/go-agent/internal" 46 47 func init() { internal.TrackUsage("integration", "framework", "grpc") }