github.com/koko1123/flow-go-1@v0.29.6/module/tracer.go (about)

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