Documentation ¶
Overview ¶
Package grpc provides functions to trace the google.golang.org/grpc package v1.2.
Example (Client) ¶
package main import ( "log" grpctrace "gopkg.in/daangn/dd-trace-go.v1/contrib/google.golang.org/grpc.v12" "google.golang.org/grpc" ) func main() { // Create the client interceptor using the grpc trace package. i := grpctrace.UnaryClientInterceptor(grpctrace.WithServiceName("my-grpc-client")) // Dial in using the created interceptor... conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithUnaryInterceptor(i)) if err != nil { log.Fatal(err) } defer conn.Close() // And continue using the connection as normal. }
Output:
Example (Server) ¶
package main import ( "log" "net" grpctrace "gopkg.in/daangn/dd-trace-go.v1/contrib/google.golang.org/grpc.v12" "google.golang.org/grpc" ) func main() { // Create a listener for the server. ln, err := net.Listen("tcp", ":50051") if err != nil { log.Fatal(err) } // Create the unary server interceptor using the grpc trace package. i := grpctrace.UnaryServerInterceptor(grpctrace.WithServiceName("my-grpc-client")) // Initialize the grpc server as normal, using the tracing interceptor. s := grpc.NewServer(grpc.UnaryInterceptor(i)) // ... register your services // Start serving incoming connections. if err := s.Serve(ln); err != nil { log.Fatalf("failed to serve: %v", err) } }
Output:
Index ¶
- Variables
- func RegisterFixtureServer(s grpc.ServiceRegistrar, srv FixtureServer)
- func UnaryClientInterceptor(opts ...InterceptorOption) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(opts ...InterceptorOption) grpc.UnaryServerInterceptor
- type FixtureClient
- type FixtureReply
- type FixtureRequest
- type FixtureServer
- type InterceptorOption
- type UnimplementedFixtureServer
- type UnsafeFixtureServer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var File_fixtures_test_proto protoreflect.FileDescriptor
Functions ¶
func RegisterFixtureServer ¶
func RegisterFixtureServer(s grpc.ServiceRegistrar, srv FixtureServer)
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(opts ...InterceptorOption) grpc.UnaryClientInterceptor
UnaryClientInterceptor will add tracing to a grpc client.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(opts ...InterceptorOption) grpc.UnaryServerInterceptor
UnaryServerInterceptor will trace requests to the given grpc server.
Types ¶
type FixtureClient ¶
type FixtureClient interface {
Ping(ctx context.Context, in *FixtureRequest, opts ...grpc.CallOption) (*FixtureReply, error)
}
FixtureClient is the client API for Fixture service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewFixtureClient ¶
func NewFixtureClient(cc grpc.ClientConnInterface) FixtureClient
type FixtureReply ¶
type FixtureReply struct { Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` // contains filtered or unexported fields }
The response message containing the greetings
func (*FixtureReply) Descriptor
deprecated
func (*FixtureReply) Descriptor() ([]byte, []int)
Deprecated: Use FixtureReply.ProtoReflect.Descriptor instead.
func (*FixtureReply) GetMessage ¶
func (x *FixtureReply) GetMessage() string
func (*FixtureReply) ProtoMessage ¶
func (*FixtureReply) ProtoMessage()
func (*FixtureReply) ProtoReflect ¶ added in v1.28.0
func (x *FixtureReply) ProtoReflect() protoreflect.Message
func (*FixtureReply) Reset ¶
func (x *FixtureReply) Reset()
func (*FixtureReply) String ¶
func (x *FixtureReply) String() string
type FixtureRequest ¶
type FixtureRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // contains filtered or unexported fields }
The request message containing the user's name.
func (*FixtureRequest) Descriptor
deprecated
func (*FixtureRequest) Descriptor() ([]byte, []int)
Deprecated: Use FixtureRequest.ProtoReflect.Descriptor instead.
func (*FixtureRequest) GetName ¶
func (x *FixtureRequest) GetName() string
func (*FixtureRequest) ProtoMessage ¶
func (*FixtureRequest) ProtoMessage()
func (*FixtureRequest) ProtoReflect ¶ added in v1.28.0
func (x *FixtureRequest) ProtoReflect() protoreflect.Message
func (*FixtureRequest) Reset ¶
func (x *FixtureRequest) Reset()
func (*FixtureRequest) String ¶
func (x *FixtureRequest) String() string
type FixtureServer ¶
type FixtureServer interface { Ping(context.Context, *FixtureRequest) (*FixtureReply, error) // contains filtered or unexported methods }
FixtureServer is the server API for Fixture service. All implementations must embed UnimplementedFixtureServer for forward compatibility
type InterceptorOption ¶
type InterceptorOption func(*interceptorConfig)
InterceptorOption represents an option that can be passed to the grpc unary client and server interceptors.
func WithAnalytics ¶ added in v1.11.0
func WithAnalytics(on bool) InterceptorOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶ added in v1.11.0
func WithAnalyticsRate(rate float64) InterceptorOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithServiceName ¶
func WithServiceName(name string) InterceptorOption
WithServiceName sets the given service name for the intercepted client.
type UnimplementedFixtureServer ¶ added in v1.28.0
type UnimplementedFixtureServer struct { }
UnimplementedFixtureServer must be embedded to have forward compatible implementations.
func (UnimplementedFixtureServer) Ping ¶ added in v1.28.0
func (UnimplementedFixtureServer) Ping(context.Context, *FixtureRequest) (*FixtureReply, error)
type UnsafeFixtureServer ¶ added in v1.28.0
type UnsafeFixtureServer interface {
// contains filtered or unexported methods
}
UnsafeFixtureServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to FixtureServer will result in compilation errors.