code: func NewTracer(opts ...TracerOption) goa.Middleware {
  	o := &tracerOptions{
  		traceIDFunc:     shortID,
  		spanIDFunc:      shortID,
  		samplingPercent: 100,
  		sampleSize:      1000, // only applies if maxSamplingRate is set
  	}
  	for _, opt := range opts {
  		o = opt(o)
  	}
  	var sampler Sampler
  	if o.maxSamplingRate > 0 {
  		sampler = NewAdaptiveSampler(o.maxSamplingRate, o.sampleSize)
  	} else {
  		sampler = NewFixedSampler(o.samplingPercent)
  	}
  	return func(h goa.Handler) goa.Handler {
  		return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
  			// insert a new trace ID only if not already being traced.
  			traceID := req.Header.Get(TraceIDHeader)
  			if traceID == "" {
  				// insert tracing only within sample.
  				if sampler.Sample() {
  					traceID = o.traceIDFunc()
  				} else {
  					return h(ctx, rw, req)
  				}
  			}
  
  			// insert IDs into context to enable tracing.
  			spanID := o.spanIDFunc()
  			parentID := req.Header.Get(ParentSpanIDHeader)
  			ctx = WithTrace(ctx, traceID, spanID, parentID)
  			return h(ctx, rw, req)
  		}
  	}
  }
docs: // NewTracer returns a trace middleware that initializes the trace information
  // in the request context. The information can be retrieved using any of the
  // ContextXXX functions.
  //
  // samplingPercent must be a value between 0 and 100. It represents the percentage
  // of requests that should be traced. If the incoming request has a Trace ID
  // header then the sampling rate is disregarded and the tracing is enabled.
  //
  // spanIDFunc and traceIDFunc are the functions used to create Span and Trace
  // IDs respectively. This is configurable so that the created IDs are compatible
  // with the various backend tracing systems. The xray package provides
  // implementations that produce AWS X-Ray compatible IDs.