Skip to content

fix: batch shutdown flush - #1731

Merged
fractalwrench merged 2 commits into
open-telemetry:mainfrom
JoaoReis153:fix/batch-shutdown-flush
Nov 27, 2026
Merged

fractalwrench merged 2 commits into
open-telemetry:mainfrom
JoaoReis153:fix/batch-shutdown-flush

Conversation

@JoaoReis153

Copy link
Copy Markdown
Contributor

Fixes #1695.

Calls the exporter's forceFlush() when the batch span and log record processors shut down, after exporting the queued telemetry and before exporter.shutdown().

What changed

  • BatchTelemetryProcessor.shutdown() now flushes the exporter once the worker has drained the queue, so both batch processors get the fix.
  • shutdown() now returns Failure if the exporter's flush fails or times out. The flush runs within the existing shutdown timeout, so it doesn't extend how long shutdown can take.

Tests

  • New shutdown cases in BatchTelemetryProcessorTest: export then flush, a failing flush, a flush timeout, and a second shutdown not flushing again.
  • BatchSpanProcessorImplTest and BatchLogRecordProcessorImplTest now expect a flush before shutdown.

@JoaoReis153
JoaoReis153 requested a review from a team as a code owner November 26, 2026 22:31
@JoaoReis153 JoaoReis153 changed the title Fix/batch shutdown flush fix: batch shutdown flush Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (4950fed) to head (13f8aa4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1731      +/-   ##
==========================================
+ Coverage   91.24%   91.25%   +0.01%     
==========================================
  Files         578      578              
  Lines        9228     9228              
  Branches     1684     1684              
==========================================
+ Hits         8420     8421       +1     
  Misses        407      407              
+ Partials      401      400       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change that flushes batch exporters after draining telemetry and before shutdown.

No open issues 🎉

What changed in this PR

Fixes #1695 by making batch span and log processors flush the exporter during shutdown, after draining queued telemetry and before exporter shutdown, aligning with OpenTelemetry requirements.

Changes:

  • Adds exporter flushing within the existing shutdown timeout and propagates flush failures.
  • Adds tests for export-before-flush ordering, flush exceptions, timeouts, and repeated shutdown.
  • Updates span and log processor tests to expect flushing before exporter shutdown.
File Description
exporters-core/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​tracing/​export/​BatchSpanProcessorImplTest.kt Expects exporter flushing before span processor shutdown.
exporters-core/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​logging/​export/​BatchLogRecordProcessorImplTest.kt Expects exporter flushing before log processor shutdown.
exporters-core/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchTelemetryProcessorTest.kt Adds shutdown flush ordering, failure, timeout, and repeat-call coverage.
exporters-core/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchTelemetryProcessor.kt Calls the guarded exporter flush after the worker drains the queue.

Review effort: Balanced

@fractalwrench fractalwrench left a comment

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.

LGTM - thanks!

@fractalwrench
fractalwrench merged commit aef33a0 into open-telemetry:main Nov 27, 2026
11 checks passed
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.

Batch span/log processors don't call the exporter's forceFlush() during shutdown()

3 participants