github.com/koko1123/flow-go-1@v0.29.6/fvm/tracing/tracer_span.go (about)

     1  package tracing
     2  
     3  import (
     4  	otelTrace "go.opentelemetry.io/otel/trace"
     5  
     6  	"github.com/koko1123/flow-go-1/module"
     7  	"github.com/koko1123/flow-go-1/module/trace"
     8  )
     9  
    10  type TracerSpan struct {
    11  	module.Tracer
    12  
    13  	otelTrace.Span
    14  
    15  	ExtensiveTracing bool
    16  }
    17  
    18  func NewTracerSpan() TracerSpan {
    19  	return TracerSpan{}
    20  }
    21  
    22  func NewMockTracerSpan() TracerSpan {
    23  	return TracerSpan{
    24  		Span: trace.NoopSpan,
    25  	}
    26  }
    27  
    28  func (tracer TracerSpan) isTraceable() bool {
    29  	return tracer.Tracer != nil && tracer.Span != nil
    30  }
    31  
    32  func (tracer TracerSpan) StartChildSpan(
    33  	name trace.SpanName,
    34  	options ...otelTrace.SpanStartOption,
    35  ) TracerSpan {
    36  	child := trace.NoopSpan
    37  	if tracer.isTraceable() {
    38  		child = tracer.Tracer.StartSpanFromParent(tracer.Span, name, options...)
    39  	}
    40  
    41  	return TracerSpan{
    42  		Tracer:           tracer.Tracer,
    43  		Span:             child,
    44  		ExtensiveTracing: tracer.ExtensiveTracing,
    45  	}
    46  }
    47  
    48  func (tracer TracerSpan) StartExtensiveTracingChildSpan(
    49  	name trace.SpanName,
    50  	options ...otelTrace.SpanStartOption,
    51  ) TracerSpan {
    52  	child := trace.NoopSpan
    53  	if tracer.isTraceable() && tracer.ExtensiveTracing {
    54  		child = tracer.Tracer.StartSpanFromParent(tracer.Span, name, options...)
    55  	}
    56  
    57  	return TracerSpan{
    58  		Tracer:           tracer.Tracer,
    59  		Span:             child,
    60  		ExtensiveTracing: tracer.ExtensiveTracing,
    61  	}
    62  }