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
Unexport the simple and batch SpanProcessors (#1638)
* Unexport the simple and batch SpanProcessors * Update changes in changelog
This commit is contained in:
@ -57,9 +57,9 @@ type BatchSpanProcessorOptions struct {
|
||||
BlockOnQueueFull bool
|
||||
}
|
||||
|
||||
// BatchSpanProcessor is a SpanProcessor that batches asynchronously-received
|
||||
// batchSpanProcessor is a SpanProcessor that batches asynchronously-received
|
||||
// SpanSnapshots and sends them to a trace.Exporter when complete.
|
||||
type BatchSpanProcessor struct {
|
||||
type batchSpanProcessor struct {
|
||||
e export.SpanExporter
|
||||
o BatchSpanProcessorOptions
|
||||
|
||||
@ -74,16 +74,13 @@ type BatchSpanProcessor struct {
|
||||
stopCh chan struct{}
|
||||
}
|
||||
|
||||
var _ SpanProcessor = (*BatchSpanProcessor)(nil)
|
||||
var _ SpanProcessor = (*batchSpanProcessor)(nil)
|
||||
|
||||
// NewBatchSpanProcessor creates a new BatchSpanProcessor that will send
|
||||
// SpanSnapshot batches to the exporters with the supplied options.
|
||||
//
|
||||
// The returned BatchSpanProcessor needs to be registered with the SDK using
|
||||
// the RegisterSpanProcessor method for it to process spans.
|
||||
// NewBatchSpanProcessor creates a new SpanProcessor that will send completed
|
||||
// span batches to the exporter with the supplied options.
|
||||
//
|
||||
// If the exporter is nil, the span processor will preform no action.
|
||||
func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanProcessorOption) *BatchSpanProcessor {
|
||||
func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanProcessorOption) SpanProcessor {
|
||||
o := BatchSpanProcessorOptions{
|
||||
BatchTimeout: DefaultBatchTimeout,
|
||||
MaxQueueSize: DefaultMaxQueueSize,
|
||||
@ -92,7 +89,7 @@ func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanPro
|
||||
for _, opt := range options {
|
||||
opt(&o)
|
||||
}
|
||||
bsp := &BatchSpanProcessor{
|
||||
bsp := &batchSpanProcessor{
|
||||
e: exporter,
|
||||
o: o,
|
||||
batch: make([]*export.SpanSnapshot, 0, o.MaxExportBatchSize),
|
||||
@ -112,10 +109,10 @@ func NewBatchSpanProcessor(exporter export.SpanExporter, options ...BatchSpanPro
|
||||
}
|
||||
|
||||
// OnStart method does nothing.
|
||||
func (bsp *BatchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {}
|
||||
func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {}
|
||||
|
||||
// OnEnd method enqueues a ReadOnlySpan for later processing.
|
||||
func (bsp *BatchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
// Do not enqueue spans if we are just going to drop them.
|
||||
if bsp.e == nil {
|
||||
return
|
||||
@ -125,7 +122,7 @@ func (bsp *BatchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
|
||||
// Shutdown flushes the queue and waits until all spans are processed.
|
||||
// It only executes once. Subsequent call does nothing.
|
||||
func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
|
||||
func (bsp *batchSpanProcessor) Shutdown(ctx context.Context) error {
|
||||
var err error
|
||||
bsp.stopOnce.Do(func() {
|
||||
wait := make(chan struct{})
|
||||
@ -150,7 +147,7 @@ func (bsp *BatchSpanProcessor) Shutdown(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// ForceFlush exports all ended spans that have not yet been exported.
|
||||
func (bsp *BatchSpanProcessor) ForceFlush() {
|
||||
func (bsp *batchSpanProcessor) ForceFlush() {
|
||||
bsp.exportSpans()
|
||||
}
|
||||
|
||||
@ -179,7 +176,7 @@ func WithBlocking() BatchSpanProcessorOption {
|
||||
}
|
||||
|
||||
// exportSpans is a subroutine of processing and draining the queue.
|
||||
func (bsp *BatchSpanProcessor) exportSpans() {
|
||||
func (bsp *batchSpanProcessor) exportSpans() {
|
||||
bsp.timer.Reset(bsp.o.BatchTimeout)
|
||||
|
||||
bsp.batchMutex.Lock()
|
||||
@ -196,7 +193,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 BatchTimeout to form a batch.
|
||||
func (bsp *BatchSpanProcessor) processQueue() {
|
||||
func (bsp *batchSpanProcessor) processQueue() {
|
||||
defer bsp.timer.Stop()
|
||||
|
||||
for {
|
||||
@ -222,7 +219,7 @@ func (bsp *BatchSpanProcessor) processQueue() {
|
||||
|
||||
// drainQueue awaits the any caller that had added to bsp.stopWait
|
||||
// to finish the enqueue, then exports the final batch.
|
||||
func (bsp *BatchSpanProcessor) drainQueue() {
|
||||
func (bsp *batchSpanProcessor) drainQueue() {
|
||||
for {
|
||||
select {
|
||||
case sd := <-bsp.queue:
|
||||
@ -245,7 +242,7 @@ func (bsp *BatchSpanProcessor) drainQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
func (bsp *BatchSpanProcessor) enqueue(sd *export.SpanSnapshot) {
|
||||
func (bsp *batchSpanProcessor) enqueue(sd *export.SpanSnapshot) {
|
||||
if !sd.SpanContext.IsSampled() {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user