...

Source file src/github.com/go-kit/kit/tracing/zipkin/options.go

Documentation: github.com/go-kit/kit/tracing/zipkin

     1  package zipkin
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/go-kit/log"
     7  )
     8  
     9  // TracerOption allows for functional options to our Zipkin tracing middleware.
    10  type TracerOption func(o *tracerOptions)
    11  
    12  // Name sets the name for an instrumented transport endpoint. If name is omitted
    13  // at tracing middleware creation, the method of the transport or transport rpc
    14  // name is used.
    15  func Name(name string) TracerOption {
    16  	return func(o *tracerOptions) {
    17  		o.name = name
    18  	}
    19  }
    20  
    21  // Tags adds default tags to our Zipkin transport spans.
    22  func Tags(tags map[string]string) TracerOption {
    23  	return func(o *tracerOptions) {
    24  		for k, v := range tags {
    25  			o.tags[k] = v
    26  		}
    27  	}
    28  }
    29  
    30  // Logger adds a Go kit logger to our Zipkin Middleware to log SpanContext
    31  // extract / inject errors if they occur. Default is Noop.
    32  func Logger(logger log.Logger) TracerOption {
    33  	return func(o *tracerOptions) {
    34  		if logger != nil {
    35  			o.logger = logger
    36  		}
    37  	}
    38  }
    39  
    40  // AllowPropagation instructs the tracer to allow or deny propagation of the
    41  // span context between this instrumented client or service and its peers. If
    42  // the instrumented client connects to services outside its own platform or if
    43  // the instrumented service receives requests from untrusted clients it is
    44  // strongly advised to disallow propagation. Propagation between services inside
    45  // your own platform benefit from propagation. Default for both TraceClient and
    46  // TraceServer is to allow propagation.
    47  func AllowPropagation(propagate bool) TracerOption {
    48  	return func(o *tracerOptions) {
    49  		o.propagate = propagate
    50  	}
    51  }
    52  
    53  // RequestSampler allows one to set the sampling decision based on the details
    54  // found in the http.Request.
    55  func RequestSampler(sampleFunc func(r *http.Request) bool) TracerOption {
    56  	return func(o *tracerOptions) {
    57  		o.requestSampler = sampleFunc
    58  	}
    59  }
    60  
    61  type tracerOptions struct {
    62  	tags           map[string]string
    63  	name           string
    64  	logger         log.Logger
    65  	propagate      bool
    66  	requestSampler func(r *http.Request) bool
    67  }
    68  

View as plain text