...

Source file src/github.com/go-kit/kit/tracing/opencensus/tracer_options.go

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

     1  package opencensus
     2  
     3  import (
     4  	"go.opencensus.io/plugin/ochttp/propagation/b3"
     5  	"go.opencensus.io/trace"
     6  	"go.opencensus.io/trace/propagation"
     7  )
     8  
     9  // defaultHTTPPropagate holds OpenCensus' default HTTP propagation format which
    10  // currently is Zipkin's B3.
    11  var defaultHTTPPropagate propagation.HTTPFormat = &b3.HTTPFormat{}
    12  
    13  // TracerOption allows for functional options to our OpenCensus tracing
    14  // middleware.
    15  type TracerOption func(o *TracerOptions)
    16  
    17  // WithTracerConfig sets all configuration options at once.
    18  func WithTracerConfig(options TracerOptions) TracerOption {
    19  	return func(o *TracerOptions) {
    20  		*o = options
    21  	}
    22  }
    23  
    24  // WithSampler sets the sampler to use by our OpenCensus Tracer.
    25  func WithSampler(sampler trace.Sampler) TracerOption {
    26  	return func(o *TracerOptions) {
    27  		o.Sampler = sampler
    28  	}
    29  }
    30  
    31  // WithName sets the name for an instrumented transport endpoint. If name is omitted
    32  // at tracing middleware creation, the method of the transport or transport rpc
    33  // name is used.
    34  func WithName(name string) TracerOption {
    35  	return func(o *TracerOptions) {
    36  		o.Name = name
    37  	}
    38  }
    39  
    40  // IsPublic should be set to true for publicly accessible servers and for
    41  // clients that should not propagate their current trace metadata.
    42  // On the server side a new trace will always be started regardless of any
    43  // trace metadata being found in the incoming request. If any trace metadata
    44  // is found, it will be added as a linked trace instead.
    45  func IsPublic(isPublic bool) TracerOption {
    46  	return func(o *TracerOptions) {
    47  		o.Public = isPublic
    48  	}
    49  }
    50  
    51  // WithHTTPPropagation sets the propagation handlers for the HTTP transport
    52  // middlewares. If used on a non HTTP transport this is a noop.
    53  func WithHTTPPropagation(p propagation.HTTPFormat) TracerOption {
    54  	return func(o *TracerOptions) {
    55  		if p == nil {
    56  			// reset to default OC HTTP format
    57  			o.HTTPPropagate = defaultHTTPPropagate
    58  			return
    59  		}
    60  		o.HTTPPropagate = p
    61  	}
    62  }
    63  
    64  // TracerOptions holds configuration for our tracing middlewares
    65  type TracerOptions struct {
    66  	Sampler       trace.Sampler
    67  	Name          string
    68  	Public        bool
    69  	HTTPPropagate propagation.HTTPFormat
    70  }
    71  

View as plain text