@@ -36,9 +36,10 @@ const (
36
36
DefaultScheduleDelay = 5000
37
37
DefaultExportTimeout = 30000
38
38
DefaultMaxExportBatchSize = 512
39
- SpansReceivedCounter = "hypertrace.agent.bsp.spans_received"
40
- SpansDroppedCounter = "hypertrace.agent.bsp.spans_dropped"
41
- SpansUnSampledCounter = "hypertrace.agent.bsp.spans_unsampled"
39
+ spansReceivedCounterName = "hypertrace.agent.bsp.spans_received"
40
+ spansDroppedCounterName = "hypertrace.agent.bsp.spans_dropped"
41
+ spansUnsampledCounterName = "hypertrace.agent.bsp.spans_unsampled"
42
+ meterName = "go.opentelemetry.io/otel/sdk/trace"
42
43
)
43
44
44
45
// batchSpanProcessor is a SpanProcessor that batches asynchronously-received
@@ -57,7 +58,9 @@ type batchSpanProcessor struct {
57
58
stopOnce sync.Once
58
59
stopCh chan struct {}
59
60
// Some metrics in here.
60
- counters map [string ]instrument.Int64Counter
61
+ spansReceivedCounter instrument.Int64Counter
62
+ spansDroppedCounter instrument.Int64Counter
63
+ spansUnsampledCounter instrument.Int64Counter
61
64
}
62
65
63
66
var _ sdktrace.SpanProcessor = (* batchSpanProcessor )(nil )
@@ -90,39 +93,36 @@ func NewBatchSpanProcessor(exporter sdktrace.SpanExporter, options ...sdktrace.B
90
93
91
94
// Setup metrics
92
95
mp := metricglobal .MeterProvider ()
93
- meter := mp .Meter ("go.opentelemetry.io/otel/sdk/trace" ,
94
- metric .WithInstrumentationVersion (otel .Version ()))
95
- counters := make (map [string ]instrument.Int64Counter )
96
+ meter := mp .Meter (meterName , metric .WithInstrumentationVersion (otel .Version ()))
96
97
97
98
// Spans received by processor
98
- spansReceivedCounter , err := meter .Int64Counter (SpansReceivedCounter )
99
+ spansReceivedCounter , err := meter .Int64Counter (spansReceivedCounterName )
99
100
if err != nil {
100
101
otel .Handle (err )
101
102
}
102
- counters [SpansReceivedCounter ] = spansReceivedCounter
103
103
104
104
// Spans Dropped by processor once the buffer is full.
105
- spansDroppedCounter , err := meter .Int64Counter (SpansDroppedCounter )
105
+ spansDroppedCounter , err := meter .Int64Counter (spansDroppedCounterName )
106
106
if err != nil {
107
107
otel .Handle (err )
108
108
}
109
- counters [SpansDroppedCounter ] = spansDroppedCounter
110
109
111
110
// Spans that are not sampled.(Useful to know when sampling is enabled)
112
- spansUnSampledCounter , err := meter .Int64Counter (SpansUnSampledCounter )
111
+ spansUnsampledCounter , err := meter .Int64Counter (spansUnsampledCounterName )
113
112
if err != nil {
114
113
otel .Handle (err )
115
114
}
116
- counters [SpansUnSampledCounter ] = spansUnSampledCounter
117
115
118
116
bsp := & batchSpanProcessor {
119
- e : exporter ,
120
- o : o ,
121
- batch : make ([]sdktrace.ReadOnlySpan , 0 , o .MaxExportBatchSize ),
122
- timer : time .NewTimer (o .BatchTimeout ),
123
- queue : make (chan sdktrace.ReadOnlySpan , o .MaxQueueSize ),
124
- stopCh : make (chan struct {}),
125
- counters : counters ,
117
+ e : exporter ,
118
+ o : o ,
119
+ batch : make ([]sdktrace.ReadOnlySpan , 0 , o .MaxExportBatchSize ),
120
+ timer : time .NewTimer (o .BatchTimeout ),
121
+ queue : make (chan sdktrace.ReadOnlySpan , o .MaxQueueSize ),
122
+ stopCh : make (chan struct {}),
123
+ spansReceivedCounter : spansReceivedCounter ,
124
+ spansDroppedCounter : spansDroppedCounter ,
125
+ spansUnsampledCounter : spansUnsampledCounter ,
126
126
}
127
127
128
128
bsp .stopWait .Add (1 )
@@ -400,12 +400,12 @@ func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd s
400
400
func (bsp * batchSpanProcessor ) enqueueDrop (ctx context.Context , sd sdktrace.ReadOnlySpan ) bool {
401
401
if ! sd .SpanContext ().IsSampled () {
402
402
// Count the span as unsampled
403
- bsp .counters [ SpansUnSampledCounter ] .Add (ctx , 1 )
403
+ bsp .spansUnsampledCounter .Add (ctx , 1 )
404
404
return false
405
405
}
406
406
407
407
// Count the span as received.
408
- bsp .counters [ SpansReceivedCounter ] .Add (ctx , 1 )
408
+ bsp .spansReceivedCounter .Add (ctx , 1 )
409
409
410
410
// This ensures the bsp.queue<- below does not panic as the
411
411
// processor shuts down.
@@ -423,7 +423,7 @@ func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd sdktrace.Read
423
423
default :
424
424
atomic .AddUint32 (& bsp .dropped , 1 )
425
425
// Count the span as dropped.
426
- bsp .counters [ SpansDroppedCounter ] .Add (ctx , 1 )
426
+ bsp .spansDroppedCounter .Add (ctx , 1 )
427
427
}
428
428
return false
429
429
}
0 commit comments