You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-27 00:21:15 +02:00
Replace Ticker with Timer since Ticker does not Reset yet
This commit is contained in:
@ -158,12 +158,17 @@ func WithBlocking() BatchSpanProcessorOption {
|
|||||||
// is shut down. It calls the exporter in batches of up to MaxExportBatchSize
|
// is shut down. It calls the exporter in batches of up to MaxExportBatchSize
|
||||||
// waiting up to ScheduledDelayMillis to form a batch.
|
// waiting up to ScheduledDelayMillis to form a batch.
|
||||||
func (bsp *BatchSpanProcessor) processQueue() {
|
func (bsp *BatchSpanProcessor) processQueue() {
|
||||||
ticker := time.NewTicker(bsp.o.ScheduledDelayMillis)
|
timer := time.NewTimer(bsp.o.ScheduledDelayMillis)
|
||||||
defer ticker.Stop()
|
defer timer.Stop()
|
||||||
|
|
||||||
batch := make([]*export.SpanData, 0, bsp.o.MaxExportBatchSize)
|
batch := make([]*export.SpanData, 0, bsp.o.MaxExportBatchSize)
|
||||||
|
|
||||||
exportSpans := func() {
|
exportSpans := func() {
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
|
timer.Reset(bsp.o.ScheduledDelayMillis)
|
||||||
|
|
||||||
if len(batch) > 0 {
|
if len(batch) > 0 {
|
||||||
bsp.e.ExportSpans(context.Background(), batch)
|
bsp.e.ExportSpans(context.Background(), batch)
|
||||||
batch = batch[:0]
|
batch = batch[:0]
|
||||||
@ -175,13 +180,12 @@ loop:
|
|||||||
select {
|
select {
|
||||||
case <-bsp.stopCh:
|
case <-bsp.stopCh:
|
||||||
break loop
|
break loop
|
||||||
case <-ticker.C:
|
case <-timer.C:
|
||||||
exportSpans()
|
exportSpans()
|
||||||
case sd := <-bsp.queue:
|
case sd := <-bsp.queue:
|
||||||
if sd.SpanContext.IsSampled() {
|
if sd.SpanContext.IsSampled() {
|
||||||
batch = append(batch, sd)
|
batch = append(batch, sd)
|
||||||
if len(batch) == bsp.o.MaxExportBatchSize {
|
if len(batch) == bsp.o.MaxExportBatchSize {
|
||||||
ticker.Reset(bsp.o.ScheduledDelayMillis)
|
|
||||||
exportSpans()
|
exportSpans()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user