github.com/grafana/pyroscope@v1.18.0/pkg/metastore/tracing/util.go (about)

     1  package tracing
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/opentracing/opentracing-go"
     7  )
     8  
     9  var noopTracer = opentracing.NoopTracer{}
    10  
    11  // StartSpanFromContext starts a span only if there's a parent span in the context.
    12  // Otherwise, it returns a noop span. To be used in places where we might not have access to the original context.
    13  func StartSpanFromContext(ctx context.Context, operationName string) (opentracing.Span, context.Context) {
    14  	if opentracing.SpanFromContext(ctx) != nil {
    15  		return opentracing.StartSpanFromContext(ctx, operationName)
    16  	}
    17  	return noopTracer.StartSpan(operationName), ctx
    18  }