github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/util/opentelemetry/options.go (about)

     1  package opentelemetry
     2  
     3  // Options for opentelemetry:
     4  type Options struct {
     5  	SamplingRate         float64 // Percentage of requests to sample (0 = rely on propagated decision)
     6  	ServiceName          string  // The name of this service
     7  	TraceReporterAddress string  // The address of a reporting server
     8  }
     9  
    10  type Option func(o *Options)
    11  
    12  const (
    13  	defaultSamplingRate         = float64(0)
    14  	defaultServiceName          = "Micro"
    15  	defaultTraceReporterAddress = "localhost:6831"
    16  )
    17  
    18  // DefaultOptions returns default options:
    19  func DefaultOptions() Options {
    20  	return Options{
    21  		SamplingRate:         defaultSamplingRate,
    22  		ServiceName:          defaultServiceName,
    23  		TraceReporterAddress: defaultTraceReporterAddress,
    24  	}
    25  }
    26  
    27  // WithSamplingRate configures the sampling rate:
    28  func WithSamplingRate(samplingRate float64) Option {
    29  	return func(o *Options) {
    30  		o.SamplingRate = samplingRate
    31  	}
    32  }
    33  
    34  // WithServiceName configures the name of this service:
    35  func WithServiceName(serviceName string) Option {
    36  	return func(o *Options) {
    37  		o.ServiceName = serviceName
    38  	}
    39  }
    40  
    41  // WithTraceReporterAddress configures the address of the trace reporter:
    42  func WithTraceReporterAddress(traceReporterAddress string) Option {
    43  	return func(o *Options) {
    44  		o.TraceReporterAddress = traceReporterAddress
    45  	}
    46  }