github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/tracer.go (about)

     1  package module
     2  
     3  import (
     4  	"context"
     5  
     6  	otelTrace "go.opentelemetry.io/otel/trace"
     7  
     8  	"github.com/onflow/flow-go/model/flow"
     9  	"github.com/onflow/flow-go/module/trace"
    10  )
    11  
    12  var (
    13  	_ Tracer = &trace.Tracer{}
    14  	_ Tracer = &trace.NoopTracer{}
    15  )
    16  
    17  // Tracer interface for tracers in flow. Uses open tracing span definitions
    18  type Tracer interface {
    19  	ReadyDoneAware
    20  
    21  	// BlockRootSpan returns the block's empty root span.  The returned span
    22  	// has already ended, and should only be used for creating children span.
    23  	BlockRootSpan(blockID flow.Identifier) otelTrace.Span
    24  
    25  	// StartBlockSpan starts an span for a block, built as a child of rootSpan.
    26  	// It also returns the context including this span which can be used for
    27  	// nested calls.
    28  	StartBlockSpan(
    29  		ctx context.Context,
    30  		blockID flow.Identifier,
    31  		spanName trace.SpanName,
    32  		opts ...otelTrace.SpanStartOption,
    33  	) (
    34  		otelTrace.Span,
    35  		context.Context,
    36  	)
    37  
    38  	// StartCollectionSpan starts an span for a collection, built as a child of
    39  	// rootSpan.  It also returns the context including this span which can be
    40  	// used for nested calls.
    41  	StartCollectionSpan(
    42  		ctx context.Context,
    43  		collectionID flow.Identifier,
    44  		spanName trace.SpanName,
    45  		opts ...otelTrace.SpanStartOption,
    46  	) (
    47  		otelTrace.Span,
    48  		context.Context,
    49  	)
    50  
    51  	StartSpanFromContext(
    52  		ctx context.Context,
    53  		operationName trace.SpanName,
    54  		opts ...otelTrace.SpanStartOption,
    55  	) (
    56  		otelTrace.Span,
    57  		context.Context,
    58  	)
    59  
    60  	StartSpanFromParent(
    61  		parentSpan otelTrace.Span,
    62  		operationName trace.SpanName,
    63  		opts ...otelTrace.SpanStartOption,
    64  	) otelTrace.Span
    65  
    66  	ShouldSample(entityID flow.Identifier) bool
    67  
    68  	// StartSampledSpanFromParent starts a real span from the parent span
    69  	// if the entity should be sampled.  Otherwise, it returns a no-op span.
    70  	StartSampledSpanFromParent(
    71  		parentSpan otelTrace.Span,
    72  		entityID flow.Identifier,
    73  		operationName trace.SpanName,
    74  		opts ...otelTrace.SpanStartOption,
    75  	) otelTrace.Span
    76  
    77  	// WithSpanFromContext encapsulates executing a function within an span, i.e., it starts a span with the specified SpanName from the context,
    78  	// executes the function f, and finishes the span once the function returns.
    79  	WithSpanFromContext(
    80  		ctx context.Context,
    81  		operationName trace.SpanName,
    82  		f func(),
    83  		opts ...otelTrace.SpanStartOption,
    84  	)
    85  }