go.undefinedlabs.com/scopeagent@v0.4.2/instrumentation/grpc/options.go (about) 1 package grpc 2 3 import "github.com/opentracing/opentracing-go" 4 5 // Option instances may be used in OpenTracing(Server|Client)Interceptor 6 // initialization. 7 type Option func(o *options) 8 9 // LogPayloads returns an Option that tells the OpenTracing instrumentation to 10 // try to log application payloads in both directions. 11 func LogPayloads() Option { 12 return func(o *options) { 13 o.logPayloads = true 14 } 15 } 16 17 // SpanInclusionFunc provides an optional mechanism to decide whether or not 18 // to trace a given gRPC call. Return true to create a Span and initiate 19 // tracing, false to not create a Span and not trace. 20 // 21 // parentSpanCtx may be nil if no parent could be extraction from either the Go 22 // context.Context (on the client) or the RPC (on the server). 23 type SpanInclusionFunc func( 24 parentSpanCtx opentracing.SpanContext, 25 method string, 26 req, resp interface{}) bool 27 28 // IncludingSpans binds a IncludeSpanFunc to the options 29 func IncludingSpans(inclusionFunc SpanInclusionFunc) Option { 30 return func(o *options) { 31 o.inclusionFunc = inclusionFunc 32 } 33 } 34 35 // SpanDecoratorFunc provides an (optional) mechanism for otgrpc users to add 36 // arbitrary tags/logs/etc to the opentracing.Span associated with client 37 // and/or server RPCs. 38 type SpanDecoratorFunc func( 39 span opentracing.Span, 40 method string, 41 req, resp interface{}, 42 grpcError error) 43 44 // SpanDecorator binds a function that decorates gRPC Spans. 45 func SpanDecorator(decorator SpanDecoratorFunc) Option { 46 return func(o *options) { 47 o.decorator = decorator 48 } 49 } 50 51 // The internal-only options struct. Obviously overkill at the moment; but will 52 // scale well as production use dictates other configuration and tuning 53 // parameters. 54 type options struct { 55 logPayloads bool 56 decorator SpanDecoratorFunc 57 // May be nil. 58 inclusionFunc SpanInclusionFunc 59 } 60 61 // newOptions returns the default options. 62 func newOptions() *options { 63 return &options{ 64 logPayloads: false, 65 inclusionFunc: nil, 66 } 67 } 68 69 func (o *options) apply(opts ...Option) { 70 for _, opt := range opts { 71 opt(o) 72 } 73 }