grpc

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodName             = "grpc.method_name"
	MethodType             = "grpc.method_type"
	Status                 = "grpc.status"
	Headers                = "grpc.headers"
	Executor               = "grpc.executor"
	Authority              = "grpc.authority"
	Compressor             = "grpc.compressor"
	DeadlineMillis         = "grpc.deadline_millis"
	MaxInboundMessageSize  = "grpc.max_inbound_message_size"
	MaxOutboundMessageSize = "grpc.max_outbound_message_size"
	StreamTracerFactories  = "grpc.stream_tracer_factories"
)

Variables

This section is empty.

Functions

func Dial

func Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

func DialContext added in v0.1.6

func DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)

func GetClientInterceptors

func GetClientInterceptors() []grpc.DialOption

Get client interceptors

func GetServerInterceptors

func GetServerInterceptors() []grpc.ServerOption

Get server interceptors

func NewServer

func NewServer(opts ...grpc.ServerOption) *grpc.Server

func OpenTracingClientInterceptor

func OpenTracingClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryClientInterceptor

OpenTracingClientInterceptor returns a grpc.UnaryClientInterceptor suitable for use in a grpc.Dial call.

For example:

conn, err := grpc.Dial(
    address,
    ...,  // (existing DialOptions)
    grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)))

All gRPC client spans will inject the OpenTracing SpanContext into the gRPC metadata; they will also look in the context.Context for an active in-process parent Span and establish a ChildOf reference if such a parent Span could be found.

func OpenTracingServerInterceptor

func OpenTracingServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryServerInterceptor

OpenTracingServerInterceptor returns a grpc.UnaryServerInterceptor suitable for use in a grpc.NewServer call.

For example:

s := grpc.NewServer(
    ...,  // (existing ServerOptions)
    grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))

All gRPC server spans will look for an OpenTracing SpanContext in the gRPC metadata; if found, the server span will act as the ChildOf that RPC SpanContext.

Root or not, the server Span will be embedded in the context.Context for the application-specific gRPC handler(s) to access.

func OpenTracingStreamClientInterceptor

func OpenTracingStreamClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.StreamClientInterceptor

OpenTracingStreamClientInterceptor returns a grpc.StreamClientInterceptor suitable for use in a grpc.Dial call. The interceptor instruments streaming RPCs by creating a single span to correspond to the lifetime of the RPC's stream.

For example:

conn, err := grpc.Dial(
    address,
    ...,  // (existing DialOptions)
    grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer)))

All gRPC client spans will inject the OpenTracing SpanContext into the gRPC metadata; they will also look in the context.Context for an active in-process parent Span and establish a ChildOf reference if such a parent Span could be found.

func OpenTracingStreamServerInterceptor

func OpenTracingStreamServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.StreamServerInterceptor

OpenTracingStreamServerInterceptor returns a grpc.StreamServerInterceptor suitable for use in a grpc.NewServer call. The interceptor instruments streaming RPCs by creating a single span to correspond to the lifetime of the RPC's stream.

For example:

s := grpc.NewServer(
    ...,  // (existing ServerOptions)
    grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)))

All gRPC server spans will look for an OpenTracing SpanContext in the gRPC metadata; if found, the server span will act as the ChildOf that RPC SpanContext.

Root or not, the server Span will be embedded in the context.Context for the application-specific gRPC handler(s) to access.

func SetSpanTags

func SetSpanTags(span opentracing.Span, err error, client bool)

SetSpanTags sets one or more tags on the given span according to the error.

Types

type Class

type Class string

A Class is a set of types of outcomes (including errors) that will often be handled in the same way.

const (
	Unknown Class = "0xx"
	// Success represents outcomes that achieved the desired results.
	Success Class = "2xx"
	// ClientError represents errors that were the client's fault.
	ClientError Class = "4xx"
	// ServerError represents errors that were the server's fault.
	ServerError Class = "5xx"
)

func ErrorClass

func ErrorClass(err error) Class

ErrorClass returns the class of the given error

type Option

type Option func(o *options)

Option instances may be used in OpenTracing(Server|Client)Interceptor initialization.

func IncludingSpans

func IncludingSpans(inclusionFunc SpanInclusionFunc) Option

IncludingSpans binds a IncludeSpanFunc to the options

func LogPayloads

func LogPayloads() Option

LogPayloads returns an Option that tells the OpenTracing instrumentation to try to log application payloads in both directions.

func SpanDecorator

func SpanDecorator(decorator SpanDecoratorFunc) Option

SpanDecorator binds a function that decorates gRPC Spans.

type SpanDecoratorFunc

type SpanDecoratorFunc func(
	span opentracing.Span,
	method string,
	req, resp interface{},
	grpcError error)

SpanDecoratorFunc provides an (optional) mechanism for otgrpc users to add arbitrary tags/logs/etc to the opentracing.Span associated with client and/or server RPCs.

type SpanInclusionFunc

type SpanInclusionFunc func(
	parentSpanCtx opentracing.SpanContext,
	method string,
	req, resp interface{}) bool

SpanInclusionFunc provides an optional mechanism to decide whether or not to trace a given gRPC call. Return true to create a Span and initiate tracing, false to not create a Span and not trace.

parentSpanCtx may be nil if no parent could be extraction from either the Go context.Context (on the client) or the RPC (on the server).

Jump to

Keyboard shortcuts

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