gitlab.com/gitlab-org/labkit@v1.21.0/tracing/sampling.go (about)

     1  package tracing
     2  
     3  import (
     4  	"github.com/opentracing/opentracing-go"
     5  	"gitlab.com/gitlab-org/labkit/tracing/impl"
     6  )
     7  
     8  // IsSampled returns the sampling status (true/false) of a span. This function
     9  // wraps around the actual implementation in `impl` packet. Technically, we don't
    10  // need this wrapper, but the `impl` package contains detailed implementation.
    11  // Most consumers import `gitlab.com/gitlab-org/labkit/tracing`
    12  func IsSampled(span opentracing.Span) bool {
    13  	// IsSampled returns the sampling status (true/false) of a span. Most
    14  	// implementations support checking this status. Unfortunately, we hide the
    15  	// tracing implementations behind unified opentracing interfaces. The single
    16  	// input is an opentracing.Span interface. As a result, we need to type-cast it
    17  	// back to all supported implementations.
    18  	// This status is particularly useful when a span is not free to collect, or
    19  	// has to turn on some special configs. One example is Git Trace2. It's a
    20  	// built-in observability tool that provides a deeper look into Git processes.
    21  	// Enabling this feature is not expensive, but not cheap either. We don't want
    22  	// to enable it for all Git processes. So, it makes sense to collect such data
    23  	// when the parent span is sampled.
    24  	return impl.IsSampled(span)
    25  }