@@ -32,22 +32,38 @@ import (
32
32
tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
33
33
)
34
34
35
- var tagKeyInterceptorName , _ = tag .NewKey ("opencensus_interceptor" )
35
+ var (
36
+ tagKeyInterceptorName , _ = tag .NewKey ("opencensus_interceptor" )
37
+ tagKeyExporterName , _ = tag .NewKey ("opencensus_exporter" )
38
+ )
39
+
36
40
var mReceivedSpans = stats .Int64 ("oc.io/interceptor/received_spans" , "Counts the number of spans received by the interceptor" , "1" )
37
41
42
+ var itemsDistribution = view .Distribution (
43
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 12 , 14 , 16 , 18 , 20 , 25 , 30 , 35 , 40 , 45 , 50 , 60 , 70 , 80 , 90 ,
44
+ 100 , 150 , 200 , 250 , 300 , 450 , 500 , 600 , 700 , 800 , 900 , 1000 , 1200 , 1400 , 1600 , 1800 , 2000 ,
45
+ )
46
+
38
47
var ViewReceivedSpansInterceptor = & view.View {
39
48
Name : "oc.io/interceptor/received_spans" ,
40
49
Description : "The number of spans received by the interceptor" ,
41
50
Measure : mReceivedSpans ,
42
- Aggregation : view .Distribution (
43
- 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 12 , 14 , 16 , 18 , 20 , 25 , 30 , 35 , 40 , 45 , 50 , 60 , 70 , 80 , 90 ,
44
- 100 , 150 , 200 , 250 , 300 , 450 , 500 , 600 , 700 , 800 , 900 , 1000 , 1200 , 1400 , 1600 , 1800 , 2000 ,
45
- ),
46
- TagKeys : []tag.Key {tagKeyInterceptorName },
51
+ Aggregation : itemsDistribution ,
52
+ TagKeys : []tag.Key {tagKeyInterceptorName },
53
+ }
54
+
55
+ var mExportedSpans = stats .Int64 ("oc.io/interceptor/exported_spans" , "Counts the number of exported spans" , "1" )
56
+ var ViewExportedSpans = & view.View {
57
+ Name : "oc.io/interceptor/exported_spans" ,
58
+ Description : "Tracks the number of exported spans" ,
59
+ Measure : mExportedSpans ,
60
+ Aggregation : itemsDistribution ,
61
+ TagKeys : []tag.Key {tagKeyExporterName },
47
62
}
48
63
49
64
var AllViews = []* view.View {
50
65
ViewReceivedSpansInterceptor ,
66
+ ViewExportedSpans ,
51
67
}
52
68
53
69
// ContextWithInterceptorName adds the tag "opencensus_interceptor" and the name of the
@@ -73,6 +89,16 @@ func NewReceivedSpansRecorderStreaming(lifetimeCtx context.Context, interceptorN
73
89
}
74
90
}
75
91
92
+ // NewExportedSpansRecorder creates a helper function that'll add the name of the
93
+ // creating exporter as a tag value in the context that will be used to count the
94
+ // the number of spans exported.
95
+ func NewExportedSpansRecorder (exporterName string ) func (context.Context , * commonpb.Node , []* tracepb.Span ) {
96
+ return func (ctx context.Context , ni * commonpb.Node , spans []* tracepb.Span ) {
97
+ ctx , _ = tag .New (ctx , tag .Upsert (tagKeyExporterName , exporterName ))
98
+ stats .Record (ctx , mExportedSpans .M (int64 (len (spans ))))
99
+ }
100
+ }
101
+
76
102
// GRPCServerWithObservabilityEnabled creates a gRPC server that at a bare minimum has
77
103
// the OpenCensus ocgrpc server stats handler enabled for tracing and stats.
78
104
// Use it instead of invoking grpc.NewServer directly.
0 commit comments