Skip to content

Commit 62e2a0f

Browse files
authored
Unexport the simple and batch SpanProcessors (#1638)
* Unexport the simple and batch SpanProcessors * Update changes in changelog
1 parent 992837f commit 62e2a0f

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
### Removed
12+
13+
- Removed the exported `SimpleSpanProcessor` and `BatchSpanProcessor` structs.
14+
These are now returned as a SpanProcessor interface from their respective constructors. (#1638)
15+
1116
## [0.18.0] - 2020-03-03
1217

1318
### Added

sdk/trace/batch_span_processor.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ type BatchSpanProcessorOptions struct {
5757
BlockOnQueueFull bool
5858
}
5959

60-
// BatchSpanProcessor is a SpanProcessor that batches asynchronously-received
60+
// batchSpanProcessor is a SpanProcessor that batches asynchronously-received
6161
// SpanSnapshots and sends them to a trace.Exporter when complete.
62-
type BatchSpanProcessor struct {
62+
type batchSpanProcessor struct {
6363
e export.SpanExporter
6464
o BatchSpanProcessorOptions
6565

@@ -74,16 +74,13 @@ type BatchSpanProcessor struct {
7474
stopCh chan struct{}
7575
}
7676

77-
var _ SpanProcessor = (*BatchSpanProcessor)(nil)
77+
var _ SpanProcessor = (*batchSpanProcessor)(nil)
7878

79-
// NewBatchSpanProcessor creates a new BatchSpanProcessor that will send
80-
// SpanSnapshot batches to the exporters with the supplied options.
81-
//
82-
// The returned BatchSpanProcessor needs to be registered with the SDK using
83-
// the RegisterSpanProcessor method for it to process spans.
79+
// NewBatchSpanProcessor creates a new SpanProcessor that will send completed
80+
// span batches to the exporter with the supplied options.
8481
//
8582
// If the exporter is nil, the span processor will preform no action.
86-
func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanProcessorOption) *BatchSpanProcessor {
83+
func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanProcessorOption) SpanProcessor {
8784
o := BatchSpanProcessorOptions{
8885
BatchTimeout: DefaultBatchTimeout,
8986
MaxQueueSize: DefaultMaxQueueSize,
@@ -92,7 +89,7 @@ func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanPro
9289
for _, opt := range options {
9390
opt(&o)
9491
}
95-
bsp := &BatchSpanProcessor{
92+
bsp := &batchSpanProcessor{
9693
e: exporter,
9794
o: o,
9895
batch: make([]*export.SpanSnapshot, 0, o.MaxExportBatchSize),
@@ -112,10 +109,10 @@ func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanPro
112109
}
113110

114111
// OnStart method does nothing.
115-
func (bsp *BatchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {}
112+
func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {}
116113

117114
// OnEnd method enqueues a ReadOnlySpan for later processing.
118-
func (bsp *BatchSpanProcessor) OnEnd(s ReadOnlySpan) {
115+
func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
119116
// Do not enqueue spans if we are just going to drop them.
120117
if bsp.e == nil {
121118
return
@@ -125,7 +122,7 @@ func (bsp *BatchSpanProcessor) OnEnd(s ReadOnlySpan) {
125122

126123
// Shutdown flushes the queue and waits until all spans are processed.
127124
// It only executes once. Subsequent call does nothing.
128-
func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
125+
func (bsp *batchSpanProcessor) Shutdown(ctx context.Context) error {
129126
var err error
130127
bsp.stopOnce.Do(func() {
131128
wait := make(chan struct{})
@@ -150,7 +147,7 @@ func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
150147
}
151148

152149
// ForceFlush exports all ended spans that have not yet been exported.
153-
func (bsp *BatchSpanProcessor) ForceFlush() {
150+
func (bsp *batchSpanProcessor) ForceFlush() {
154151
bsp.exportSpans()
155152
}
156153

@@ -179,7 +176,7 @@ func WithBlocking() BatchSpanProcessorOption {
179176
}
180177

181178
// exportSpans is a subroutine of processing and draining the queue.
182-
func (bsp *BatchSpanProcessor) exportSpans() {
179+
func (bsp *batchSpanProcessor) exportSpans() {
183180
bsp.timer.Reset(bsp.o.BatchTimeout)
184181

185182
bsp.batchMutex.Lock()
@@ -196,7 +193,7 @@ func (bsp *BatchSpanProcessor) exportSpans() {
196193
// processQueue removes spans from the `queue` channel until processor
197194
// is shut down. It calls the exporter in batches of up to MaxExportBatchSize
198195
// waiting up to BatchTimeout to form a batch.
199-
func (bsp *BatchSpanProcessor) processQueue() {
196+
func (bsp *batchSpanProcessor) processQueue() {
200197
defer bsp.timer.Stop()
201198

202199
for {
@@ -222,7 +219,7 @@ func (bsp *BatchSpanProcessor) processQueue() {
222219

223220
// drainQueue awaits the any caller that had added to bsp.stopWait
224221
// to finish the enqueue, then exports the final batch.
225-
func (bsp *BatchSpanProcessor) drainQueue() {
222+
func (bsp *batchSpanProcessor) drainQueue() {
226223
for {
227224
select {
228225
case sd := <-bsp.queue:
@@ -245,7 +242,7 @@ func (bsp *BatchSpanProcessor) drainQueue() {
245242
}
246243
}
247244

248-
func (bsp *BatchSpanProcessor) enqueue(sd *export.SpanSnapshot) {
245+
func (bsp *batchSpanProcessor) enqueue(sd *export.SpanSnapshot) {
249246
if !sd.SpanContext.IsSampled() {
250247
return
251248
}

sdk/trace/batch_span_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestNewBatchSpanProcessorWithOptions(t *testing.T) {
198198
}
199199
}
200200

201-
func createAndRegisterBatchSP(option testOption, te *testBatchExporter) *sdktrace.BatchSpanProcessor {
201+
func createAndRegisterBatchSP(option testOption, te *testBatchExporter) sdktrace.SpanProcessor {
202202
// Always use blocking queue to avoid flaky tests.
203203
options := append(option.o, sdktrace.WithBlocking())
204204
return sdktrace.NewBatchSpanProcessor(te, options...)

sdk/trace/simple_span_processor.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ import (
2121
export "go.opentelemetry.io/otel/sdk/export/trace"
2222
)
2323

24-
// SimpleSpanProcessor is a SpanProcessor that synchronously sends all
24+
// simpleSpanProcessor is a SpanProcessor that synchronously sends all
2525
// SpanSnapshots to a trace.Exporter when the span finishes.
26-
type SimpleSpanProcessor struct {
26+
type simpleSpanProcessor struct {
2727
e export.SpanExporter
2828
}
2929

30-
var _ SpanProcessor = (*SimpleSpanProcessor)(nil)
30+
var _ SpanProcessor = (*simpleSpanProcessor)(nil)
3131

32-
// NewSimpleSpanProcessor returns a new SimpleSpanProcessor that will
33-
// synchronously send SpanSnapshots to the exporter.
34-
func NewSimpleSpanProcessor(exporter export.SpanExporter) *SimpleSpanProcessor {
35-
ssp := &SimpleSpanProcessor{
32+
// NewSimpleSpanProcessor returns a new SpanProcessor that will synchronously
33+
// send completed spans to the exporter immediately.
34+
func NewSimpleSpanProcessor(exporter export.SpanExporter) SpanProcessor {
35+
ssp := &simpleSpanProcessor{
3636
e: exporter,
3737
}
3838
return ssp
3939
}
4040

4141
// OnStart method does nothing.
42-
func (ssp *SimpleSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {
42+
func (ssp *simpleSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {
4343
}
4444

4545
// OnEnd method exports a ReadOnlySpan using the associated exporter.
46-
func (ssp *SimpleSpanProcessor) OnEnd(s ReadOnlySpan) {
46+
func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) {
4747
if ssp.e != nil && s.SpanContext().IsSampled() {
4848
ss := s.Snapshot()
4949
if err := ssp.e.ExportSpans(context.Background(), []*export.SpanSnapshot{ss}); err != nil {
@@ -53,10 +53,10 @@ func (ssp *SimpleSpanProcessor) OnEnd(s ReadOnlySpan) {
5353
}
5454

5555
// Shutdown method does nothing. There is no data to cleanup.
56-
func (ssp *SimpleSpanProcessor) Shutdown(_ context.Context) error {
56+
func (ssp *simpleSpanProcessor) Shutdown(_ context.Context) error {
5757
return nil
5858
}
5959

6060
// ForceFlush does nothing as there is no data to flush.
61-
func (ssp *SimpleSpanProcessor) ForceFlush() {
61+
func (ssp *simpleSpanProcessor) ForceFlush() {
6262
}

0 commit comments

Comments
 (0)