Repository: open-telemetry/opentelemetry-go
Pull request #752 (2020-05-20 11:19:25)

Rename ScheduleDelayMillis to BatchTimeout


Patch:
diff --git a/example/zipkin/main.go b/example/zipkin/main.go
index badfae97..94e0e6e2 100644
--- a/example/zipkin/main.go
+++ b/example/zipkin/main.go
@@ -49,7 +49,7 @@ func initTracer(url string) {
 	tp, err := sdktrace.NewProvider(
 		sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
 		sdktrace.WithBatcher(exporter,
-			sdktrace.WithScheduleDelayMillis(5),
+			sdktrace.WithBatchTimeout(5),
 			sdktrace.WithMaxExportBatchSize(10),
 		),
 	)
diff --git a/sdk/trace/batch_span_processor.go b/sdk/trace/batch_span_processor.go
index 31aa6da3..4030e0a3 100644
--- a/sdk/trace/batch_span_processor.go
+++ b/sdk/trace/batch_span_processor.go
@@ -27,7 +27,7 @@ import (
 
 const (
 	DefaultMaxQueueSize       = 2048
-	DefaultScheduledDelay     = 5000 * time.Millisecond
+	DefaultBatchTimeout       = 5000 * time.Millisecond
 	DefaultMaxExportBatchSize = 512
 )
 
@@ -43,10 +43,10 @@ type BatchSpanProcessorOptions struct {
 	// The default value of MaxQueueSize is 2048.
 	MaxQueueSize int
 
-	// ScheduledDelayMillis is the delay interval in milliseconds between two consecutive
-	// processing of batches.
-	// The default value of ScheduledDelayMillis is 5000 msec.
-	ScheduledDelayMillis time.Duration
+	// BatchTimeout is the maximum duration for constructing a batch. Processor
+	// forcefully sends available spans when timeout is reached.
+	// The default value of BatchTimeout is 5000 msec.
+	BatchTimeout time.Duration
 
 	// MaxExportBatchSize is the maximum number of spans to process in a single batch.
 	// If there are more than one batch worth of spans then it processes multiple batches
@@ -90,9 +90,9 @@ func NewBatchSpanProcessor(e export.SpanBatcher, opts ...BatchSpanProcessorOptio
 	}
 
 	o := BatchSpanProcessorOptions{
-		ScheduledDelayMillis: DefaultScheduledDelay,
-		MaxQueueSize:         DefaultMaxQueueSize,
-		MaxExportBatchSize:   DefaultMaxExportBatchSize,
+		BatchTimeout:       DefaultBatchTimeout,
+		MaxQueueSize:       DefaultMaxQueueSize,
+		MaxExportBatchSize: DefaultMaxExportBatchSize,
 	}
 	for _, opt := range opts {
 		opt(&o)
@@ -101,7 +101,7 @@ func NewBatchSpanProcessor(e export.SpanBatcher, opts ...BatchSpanProcessorOptio
 		e:      e,
 		o:      o,
 		batch:  make([]*export.SpanData, 0, o.MaxExportBatchSize),
-		timer:  time.NewTimer(o.ScheduledDelayMillis),
+		timer:  time.NewTimer(o.BatchTimeout),
 		queue:  make(chan *export.SpanData, o.MaxQueueSize),
 		stopCh: make(chan struct{}),
 	}
@@ -147,9 +147,9 @@ func WithMaxExportBatchSize(size int) BatchSpanProcessorOption {
 	}
 }
 
-func WithScheduleDelayMillis(delay time.Duration) BatchSpanProcessorOption {
+func WithBatchTimeout(delay time.Duration) BatchSpanProcessorOption {
 	return func(o *BatchSpanProcessorOptions) {
-		o.ScheduledDelayMillis = delay
+		o.BatchTimeout = delay
 	}
 }
 
@@ -161,7 +161,7 @@ func WithBlocking() BatchSpanProcessorOption {
 
 // exportSpans is a subroutine of processing and draining the queue.
 func (bsp *BatchSpanProcessor) exportSpans() {
-	bsp.timer.Reset(bsp.o.ScheduledDelayMillis)
+	bsp.timer.Reset(bsp.o.BatchTimeout)
 
 	if len(bsp.batch) > 0 {
 		bsp.e.ExportSpans(context.Background(), bsp.batch)
@@ -171,7 +171,7 @@ func (bsp *BatchSpanProcessor) exportSpans() {
 
 // processQueue removes spans from the `queue` channel until processor
 // is shut down. It calls the exporter in batches of up to MaxExportBatchSize
-// waiting up to ScheduledDelayMillis to form a batch.
+// waiting up to BatchTimeout to form a batch.
 func (bsp *BatchSpanProcessor) processQueue() {
 	defer bsp.stopWait.Done()
 	defer bsp.timer.Stop()


Test patch:
diff --git a/exporters/otlp/example_test.go b/exporters/otlp/example_test.go
index 8c0a8b85..5cf14f92 100644
--- a/exporters/otlp/example_test.go
+++ b/exporters/otlp/example_test.go
@@ -39,7 +39,7 @@ func Example_insecure() {
 	tp, _ := sdktrace.NewProvider(
 		sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
 		sdktrace.WithBatcher(exp, // add following two options to ensure flush
-			sdktrace.WithScheduleDelayMillis(5),
+			sdktrace.WithBatchTimeout(5),
 			sdktrace.WithMaxExportBatchSize(10),
 		))
 	if err != nil {
@@ -80,7 +80,7 @@ func Example_withTLS() {
 	tp, err := sdktrace.NewProvider(
 		sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
 		sdktrace.WithBatcher(exp, // add following two options to ensure flush
-			sdktrace.WithScheduleDelayMillis(5),
+			sdktrace.WithBatchTimeout(5),
 			sdktrace.WithMaxExportBatchSize(10),
 		))
 	if err != nil {
diff --git a/exporters/otlp/otlp_integration_test.go b/exporters/otlp/otlp_integration_test.go
index 04d17dbd..081437c7 100644
--- a/exporters/otlp/otlp_integration_test.go
+++ b/exporters/otlp/otlp_integration_test.go
@@ -81,7 +81,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
 	pOpts := []sdktrace.ProviderOption{
 		sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
 		sdktrace.WithBatcher(exp, // add following two options to ensure flush
-			sdktrace.WithScheduleDelayMillis(15),
+			sdktrace.WithBatchTimeout(15),
 			sdktrace.WithMaxExportBatchSize(10),
 		),
 	}
diff --git a/sdk/trace/batch_span_processor_test.go b/sdk/trace/batch_span_processor_test.go
index abc91f4c..3e80a20d 100644
--- a/sdk/trace/batch_span_processor_test.go
+++ b/sdk/trace/batch_span_processor_test.go
@@ -82,18 +82,18 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
 			genNumSpans:    2053,
 		},
 		{
-			name: "non-default ScheduledDelayMillis",
+			name: "non-default BatchTimeout",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 			},
 			wantNumSpans:   2053,
 			wantBatchCount: 4,
 			genNumSpans:    2053,
 		},
 		{
-			name: "non-default MaxQueueSize and ScheduledDelayMillis",
+			name: "non-default MaxQueueSize and BatchTimeout",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 				sdktrace.WithMaxQueueSize(200),
 			},
 			wantNumSpans:   205,
@@ -101,9 +101,9 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
 			genNumSpans:    205,
 		},
 		{
-			name: "non-default MaxQueueSize, ScheduledDelayMillis and MaxExportBatchSize",
+			name: "non-default MaxQueueSize, BatchTimeout and MaxExportBatchSize",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 				sdktrace.WithMaxQueueSize(205),
 				sdktrace.WithMaxExportBatchSize(20),
 			},
@@ -114,7 +114,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
 		{
 			name: "blocking option",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 				sdktrace.WithMaxQueueSize(200),
 				sdktrace.WithMaxExportBatchSize(20),
 				sdktrace.WithBlocking(),
@@ -126,7 +126,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
 		{
 			name: "parallel span generation",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 				sdktrace.WithMaxQueueSize(200),
 			},
 			wantNumSpans:   205,
@@ -137,7 +137,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
 		{
 			name: "parallel span blocking",
 			o: []sdktrace.BatchSpanProcessorOption{
-				sdktrace.WithScheduleDelayMillis(schDelay),
+				sdktrace.WithBatchTimeout(schDelay),
 				sdktrace.WithMaxExportBatchSize(200),
 				sdktrace.WithBlocking(),
 			},