-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty queued spans when ForceFlush called #2335
Conversation
Update the implementation of ForceFlush() to first ensure that all spans which are queued are added to the batch before calling export spans. Create a small ReadOnlySpan implementation which can be used as a marker that ForceFlush has been invoked and used to notify when all spans are ready to be exported. Fixes #2080.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the simplicity of this solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a CHANGELOG entry describing this change and sign the CLA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ForceFlush
method should not shut down the processor.
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sign the CLA so we can accept these changes.
sdk/trace/batch_span_processor.go
Outdated
// ForceFlush exports all ended spans that have not yet been exported. | ||
func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error { | ||
var err error | ||
if bsp.e != nil { | ||
flushCh := make(chan struct{}) | ||
select { | ||
case bsp.queue <- forceFlushSpan{flushed: flushCh}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the enque
method here instead to handle the shutdown case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this blocks on a full queue ... It might make sense to copy some of the logic from that method to here to handle the case where shutdown has already occurred or is concurrently happening.
There is still more that needs to be changed here.
Will do this ASAP - waiting on legal sign off. |
} | ||
|
||
func (f forceFlushSpan) SpanContext() trace.SpanContext { | ||
return trace.NewSpanContext(trace.SpanContextConfig{TraceFlags: trace.FlagsSampled}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using enqueue requires that the span being queued is marked as sampled.
sdk/trace/batch_span_processor.go
Outdated
// ForceFlush exports all ended spans that have not yet been exported. | ||
func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error { | ||
var err error | ||
if bsp.e != nil { | ||
flushCh := make(chan struct{}) | ||
bsp.enqueueBlockOnQueueFull(ctx, forceFlushSpan{flushed: flushCh}, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass true as the last argument here since we want to block for this span to be queued.
@@ -296,6 +320,10 @@ func (bsp *batchSpanProcessor) drainQueue() { | |||
} | |||
|
|||
func (bsp *batchSpanProcessor) enqueue(sd ReadOnlySpan) { | |||
bsp.enqueueBlockOnQueueFull(context.TODO(), sd, bsp.o.BlockOnQueueFull) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to work in the ForceFlush method, it was needed to pass a context (to allow cancellation).
Update the handling of the force flush span so we only wait on the channel if we were able to enqueue the span to the queue.
Sorry for delay on CLA - that is now approved. Does this need a CI build to be approved now? |
Codecov Report
@@ Coverage Diff @@
## main #2335 +/- ##
=======================================
+ Coverage 73.6% 73.8% +0.1%
=======================================
Files 175 175
Lines 12419 12436 +17
=======================================
+ Hits 9144 9179 +35
+ Misses 3041 3020 -21
- Partials 234 237 +3
|
There is a test
Is this a known flaky test? I also saw it referenced in #2285. |
I think there have been a couple attempts to address that flake test, but it has thus far eluded correction. |
Update the implementation of ForceFlush() to first ensure that all spans
which are queued are added to the batch before calling export spans.
Create a small ReadOnlySpan implementation which can be used as a marker
that ForceFlush has been invoked and used to notify when all spans are
ready to be exported.
Fixes #2080.