Skip to content

sdk/trace: batchSpanProcessor.ForceFlush calls SpanExporter.ExportSpans synchronously#6416

Closed
pellared wants to merge 9 commits intoopen-telemetry:mainfrom
pellared:refactor-leak
Closed

sdk/trace: batchSpanProcessor.ForceFlush calls SpanExporter.ExportSpans synchronously#6416
pellared wants to merge 9 commits intoopen-telemetry:mainfrom
pellared:refactor-leak

Conversation

@pellared
Copy link
Copy Markdown
Member

@pellared pellared commented Mar 6, 2025

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 6, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.8%. Comparing base (2a49562) to head (725112d).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #6416     +/-   ##
=======================================
- Coverage   81.8%   81.8%   -0.1%     
=======================================
  Files        283     283             
  Lines      24910   24903      -7     
=======================================
- Hits       20386   20378      -8     
- Misses      4119    4120      +1     
  Partials     405     405             

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines -563 to -579
func TestBatchSpanProcessorForceFlushTimeout(t *testing.T) {
tp := basicTracerProvider(t)
exp := newIndefiniteExporter(t)
bsp := NewBatchSpanProcessor(exp)
tp.RegisterSpanProcessor(bsp)
tr := tp.Tracer(t.Name())
_, span := tr.Start(context.Background(), "foo")
span.End()

// Add timeout to context to test deadline
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()

if got, want := bsp.ForceFlush(ctx), context.DeadlineExceeded; !errors.Is(got, want) {
t.Errorf("expected %q error, got %v", want, got)
}
}
Copy link
Copy Markdown
Member Author

@pellared pellared Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was verifying a scenario when SpanExporter.ExportSpans hangs. Now we would be hanging because we are calling synchronously. I think this is fine as returning prematurely leaks a goroutine.

@pellared pellared marked this pull request as ready for review March 6, 2025 07:47
Comment thread CHANGELOG.md
Comment on lines +11 to +14
### Changed

- `ForceFlush` of the `NewBatchSpanProcessor` in `go.opentelemetry.io/otel/sdk/trace` calls `SpanExporter.ExportSpans` synchronously. (#6416)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record, this is a significant change in behavior, and can easily be interpreted as a breaking change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More like this https://xkcd.com/1172/

@pellared
Copy link
Copy Markdown
Member Author

@MrAlias, @XSAM, do you have any opinions/feedback regarding this PR?

@pellared
Copy link
Copy Markdown
Member Author

SIG meeting: This can cause other issues.

@pellared pellared closed this Mar 20, 2025
@pellared pellared deleted the refactor-leak branch May 20, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants