@@ -36,9 +36,10 @@ const (
3636 DefaultScheduleDelay = 5000
3737 DefaultExportTimeout = 30000
3838 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"
4243)
4344
4445// batchSpanProcessor is a SpanProcessor that batches asynchronously-received
@@ -57,7 +58,9 @@ type batchSpanProcessor struct {
5758 stopOnce sync.Once
5859 stopCh chan struct {}
5960 // Some metrics in here.
60- counters map [string ]instrument.Int64Counter
61+ spansReceivedCounter instrument.Int64Counter
62+ spansDroppedCounter instrument.Int64Counter
63+ spansUnsampledCounter instrument.Int64Counter
6164}
6265
6366var _ sdktrace.SpanProcessor = (* batchSpanProcessor )(nil )
@@ -90,39 +93,36 @@ func NewBatchSpanProcessor(exporter sdktrace.SpanExporter, options ...sdktrace.B
9093
9194 // Setup metrics
9295 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 ()))
9697
9798 // Spans received by processor
98- spansReceivedCounter , err := meter .Int64Counter (SpansReceivedCounter )
99+ spansReceivedCounter , err := meter .Int64Counter (spansReceivedCounterName )
99100 if err != nil {
100101 otel .Handle (err )
101102 }
102- counters [SpansReceivedCounter ] = spansReceivedCounter
103103
104104 // Spans Dropped by processor once the buffer is full.
105- spansDroppedCounter , err := meter .Int64Counter (SpansDroppedCounter )
105+ spansDroppedCounter , err := meter .Int64Counter (spansDroppedCounterName )
106106 if err != nil {
107107 otel .Handle (err )
108108 }
109- counters [SpansDroppedCounter ] = spansDroppedCounter
110109
111110 // Spans that are not sampled.(Useful to know when sampling is enabled)
112- spansUnSampledCounter , err := meter .Int64Counter (SpansUnSampledCounter )
111+ spansUnsampledCounter , err := meter .Int64Counter (spansUnsampledCounterName )
113112 if err != nil {
114113 otel .Handle (err )
115114 }
116- counters [SpansUnSampledCounter ] = spansUnSampledCounter
117115
118116 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 ,
126126 }
127127
128128 bsp .stopWait .Add (1 )
@@ -400,12 +400,12 @@ func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd s
400400func (bsp * batchSpanProcessor ) enqueueDrop (ctx context.Context , sd sdktrace.ReadOnlySpan ) bool {
401401 if ! sd .SpanContext ().IsSampled () {
402402 // Count the span as unsampled
403- bsp .counters [ SpansUnSampledCounter ] .Add (ctx , 1 )
403+ bsp .spansUnsampledCounter .Add (ctx , 1 )
404404 return false
405405 }
406406
407407 // Count the span as received.
408- bsp .counters [ SpansReceivedCounter ] .Add (ctx , 1 )
408+ bsp .spansReceivedCounter .Add (ctx , 1 )
409409
410410 // This ensures the bsp.queue<- below does not panic as the
411411 // processor shuts down.
@@ -423,7 +423,7 @@ func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd sdktrace.Read
423423 default :
424424 atomic .AddUint32 (& bsp .dropped , 1 )
425425 // Count the span as dropped.
426- bsp .counters [ SpansDroppedCounter ] .Add (ctx , 1 )
426+ bsp .spansDroppedCounter .Add (ctx , 1 )
427427 }
428428 return false
429429}
0 commit comments