-
Notifications
You must be signed in to change notification settings - Fork 175
/
tracer.go
84 lines (72 loc) · 2.71 KB
/
tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package module
import (
"context"
"time"
"go.opentelemetry.io/otel/attribute"
otelTrace "go.opentelemetry.io/otel/trace"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/trace"
)
var (
_ Tracer = &trace.Tracer{}
_ Tracer = &trace.NoopTracer{}
_ Tracer = &trace.LogTracer{}
)
// Tracer interface for tracers in flow. Uses open tracing span definitions
type Tracer interface {
ReadyDoneAware
// StartBlockSpan starts an span for a block, built as a child of rootSpan
// it also returns the context including this span which can be used for nested calls.
// and also a boolean reporting if this span is sampled (is used for avoiding unncessary computation for tags)
StartBlockSpan(
ctx context.Context,
blockID flow.Identifier,
spanName trace.SpanName,
opts ...otelTrace.SpanStartOption,
) (otelTrace.Span, context.Context, bool)
// StartCollectionSpan starts an span for a collection, built as a child of rootSpan
// it also returns the context including this span which can be used for nested calls.
// and also a boolean reporting if this span is sampled (is used for avoiding unncessary computation for tags)
StartCollectionSpan(
ctx context.Context,
collectionID flow.Identifier,
spanName trace.SpanName,
opts ...otelTrace.SpanStartOption,
) (otelTrace.Span, context.Context, bool)
// StartTransactionSpan starts an span for a transaction, built as a child of rootSpan
// it also returns the context including this span which can be used for nested calls.
// and also a boolean reporting if this span is sampled (is used for avoiding unncessary computation for tags)
StartTransactionSpan(
ctx context.Context,
transactionID flow.Identifier,
spanName trace.SpanName,
opts ...otelTrace.SpanStartOption,
) (otelTrace.Span, context.Context, bool)
StartSpanFromContext(
ctx context.Context,
operationName trace.SpanName,
opts ...otelTrace.SpanStartOption,
) (otelTrace.Span, context.Context)
StartSpanFromParent(
parentSpan otelTrace.Span,
operationName trace.SpanName,
opts ...otelTrace.SpanStartOption,
) otelTrace.Span
// RecordSpanFromParent records an span at finish time
// start time will be computed by reducing time.Now() - duration
RecordSpanFromParent(
parentSpan otelTrace.Span,
operationName trace.SpanName,
duration time.Duration,
attrs []attribute.KeyValue,
opts ...otelTrace.SpanStartOption,
)
// WithSpanFromContext encapsulates executing a function within an span, i.e., it starts a span with the specified SpanName from the context,
// executes the function f, and finishes the span once the function returns.
WithSpanFromContext(
ctx context.Context,
operationName trace.SpanName,
f func(),
opts ...otelTrace.SpanStartOption,
)
}