Skip to content

feat: distinguish a timeout from other failures on shutdown and flush - #1663

Merged
fractalwrench merged 9 commits into
open-telemetry:mainfrom
leo7martins:vibe/operationresult-timeout-c40124
Nov 27, 2026
Merged

fractalwrench merged 9 commits into
open-telemetry:mainfrom
leo7martins:vibe/operationresult-timeout-c40124

Conversation

@leo7martins

Copy link
Copy Markdown
Contributor

Goal

  • Fixes Shutdown/ForceFlush results can't distinguish a timeout from a failure #1653.
  • runWithTimeout mapped TimeoutCancellationException to Failure, so callers could not tell a timeout from an exporter failure on shutdown/forceFlush.
  • OperationResultCode.Failure is now an open class whose companion is the generic failure (so existing equality checks keep working), with a Timeout subtype returned by runWithTimeout. The and combinator and batchExportOperation* preserve a timeout through aggregation (Timeout wins over a generic Failure), so composite closeables report it end to end.

Testing

  • New TimeoutOperationTest (runWithTimeout passthrough and timeout, Timeout is Failure, MutableShutdownState.shutdown, composite flush). BatchTelemetryProcessorTest and the persisting processors' over-timeout cases now assert Timeout.
  • Not run locally (no JDK available); relying on CI.

This was written with help from an AI coding assistant.

Co-authored-by: leo7martins <leo7martins@users.noreply.github.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: leo7martins / name: leo7martins (d433e63)

@leo7martins
leo7martins marked this pull request as ready for review November 23, 2026 18:08
@leo7martins
leo7martins requested a review from a team as a code owner November 23, 2026 18:08
@fractalwrench
fractalwrench requested a balanced review from Copilot November 23, 2026 18:48

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.

🟡 Changes recommended

The change introduces a non-compiling test, leaves SDK timeout assertions expecting the wrong result, and omits ABI baseline updates for a binary-incompatible API change.

3 open issues
What changed in this PR

This PR addresses #1653 by distinguishing shutdown and flush timeouts from other failures in the Kotlin Multiplatform OpenTelemetry SDK.

Changes:

  • Adds OperationResultCode.Timeout as a subtype of Failure.
  • Preserves timeout results through batch and composite aggregation, prioritizing them over generic failures.
  • Updates timeout documentation and test expectations, and adds focused lifecycle timeout tests.
File Description
sdk-common/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​export/​TimeoutOperationTest.kt Adds timeout, subtype, shutdown, and composite flush tests.
sdk-common/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​TimeoutOperation.kt Returns Timeout when the deadline expires.
sdk-common/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​MutableShutdownState.kt Documents the distinct shutdown timeout result.
sdk-common/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchExportOperation.kt Preserves timeouts when aggregating operation results.
sdk-api/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​OperationResultCode.kt Introduces the failure hierarchy and timeout subtype.
exporters-persistence/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​tracing/​export/​PersistingSpanProcessorTest.kt Updates span processor timeout expectations.
exporters-persistence/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​logging/​export/​PersistingLogRecordProcessorTest.kt Updates log processor timeout expectations.
exporters-core/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchTelemetryProcessorTest.kt Expects Timeout for an overdue flush.
exporters-core/​src/​commonMain/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchTelemetryProcessor.kt Gives timeout results precedence in the and combinator.

Review effort: Balanced

* of failure.
*/
public object Failure : OperationResultCode()
public open class Failure public constructor() : OperationResultCode() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the JVM, Android and klib dumps in fc225cc. They were generated with the Kotlin 2.4.21 ABI tools, which reproduce the existing baselines exactly for the old Failure object; apiCheck passes in CI.

On binary compatibility: c3c3ff6 keeps OperationResultCode$Failure.INSTANCE. It adds a hidden @JvmField INSTANCE on the Failure companion, so JVM binaries compiled against the old object keep working without recompiling. Kotlin sources can't see it and keep using OperationResultCode.Failure.

@fractalwrench fractalwrench added the needs author feedback Further information required from the issue/PR author label Nov 23, 2026
runWithTimeout now returns OperationResultCode.Timeout, a kind of
Failure, when the timeout elapses before the action completes, so the
existing tests that pin that path asserted the old generic Failure.
Updated:
- OpenTelemetryImplTest testShutdownExceedsTimeout and
  testForceFlushExceedsTimeout
- the 'times out if the result never completes' tests of
  CompletableResultCodeExtTest, LogRecordExporterAdapterTest,
  LogRecordProcessorAdapterTest, SpanExporterAdapterTest and
  SpanProcessorAdapterTest, which await through runWithTimeout.
Assertions about generic and exceptional failures stay Failure.
The explicit-timeout variant of awaitOperationResultCode also goes
through runWithTimeout, so when that timeout elapses the result is
OperationResultCode.Timeout under the new contract, not Failure.

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.

🔵 Needs a closer look

Removing OperationResultCode$Failure.INSTANCE breaks binary compatibility for previously compiled JVM/Android callers with NoSuchFieldError, while the checked-in ABI dumps remain inconsistent with the new public API.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Low severity Test Timeout propagation through and in both orders

exporters-core/​src/​commonTest/​kotlin/​io/​opentelemetry/​kotlin/​export/​BatchTelemetryProcessorTest.kt:241

This assertion is satisfied by the outer flush deadline, so it does not verify that and preserves an export's Timeout result. Please add a test where the worker finishes before that deadline, combining Timeout with Success and generic Failure in both orders.

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.

@leo7martins once you can address failing CI and resolve the remaining copilot comments I'd be happy with this

Failure is now an open class whose companion is the generic failure, and
Timeout is a new Failure subtype, so the JVM, Android and klib dumps are
updated to match. This drops OperationResultCode$Failure.INSTANCE on
JVM/Android, so callers compiled against the old object need a
recompile; the type is @experimentalapi.

Also drops the redundant explicit constructor on Failure, which detekt
reports as EmptyDefaultConstructor; the implicit one has the same ABI.
- Order the OperationResultCode.Timeout import after Success in the
  persisting processor tests (detekt ImportOrdering failed CI).
- Compare Failure and Timeout as OperationResultCode in
  TimeoutOperationTest rather than via their concrete object types.
- Test that the and combinator keeps Timeout in both orders against
  Success, Failure and Timeout, and that forceFlush reports an export
  or exporter-flush timeout that completes before the flush deadline.

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.

🟡 Changes recommended

Export timeouts are still mapped to Failure, causing forceFlush() to lose the timeout classification and the new timeout-reporting test to fail.

3 open issues
1 resolved since last review

Review effort: Balanced

Failure changed from an object to an open class with a companion, which
removed the static INSTANCE field that JVM binaries compiled against the
old object read. Add a @JvmField INSTANCE on the companion, hidden from
Kotlin sources, so those binaries keep working, and update the ABI dumps.
The Duration-based export timeout merged from main still returned a plain
Failure, so forceFlush reported Failure instead of Timeout when the export
itself timed out (testForceFlushReportsExportTimeout).
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.22%. Comparing base (8019891) to head (a75b8e5).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
...pentelemetry/kotlin/export/BatchExportOperation.kt 66.66% 0 Missing and 2 partials ⚠️
...opentelemetry/kotlin/export/OperationResultCode.kt 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1663      +/-   ##
==========================================
- Coverage   91.35%   91.22%   -0.14%     
==========================================
  Files         573      578       +5     
  Lines        8986     9238     +252     
  Branches     1632     1689      +57     
==========================================
+ Hits         8209     8427     +218     
- Misses        391      408      +17     
- Partials      386      403      +17     

☔ 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.

@leo7martins

Copy link
Copy Markdown
Contributor Author

Thanks @fractalwrench! CI is green now on a75b8e5. Summary of the follow-up commits:

  • f73fe28: fixes the detekt ImportOrdering failure in the two persisting-processor tests, widens the Failure/Timeout comparison, and adds testAndPreservesTimeout plus two forceFlush tests where a timeout happens before the flush deadline (Copilot's "previously missed" note).
  • fc225cc: updates the sdk-api ABI dumps and drops the empty explicit constructor on Failure, which detekt would otherwise flag.
  • 71369be / e31889f: merges main and switches the new test to the Duration-based exportTimeout.
  • c3c3ff6: keeps Failure.INSTANCE as a hidden @JvmField on the companion, so existing JVM binaries don't need recompiling.
  • a75b8e5: the Duration-based guardUserCode that came in from main (Use Duration for span batch timing #1640) still returned Failure on an export timeout; it now returns Timeout, which testForceFlushReportsExportTimeout covers.

The Copilot threads are answered inline. The full Gradle build wasn't run locally; an AI agent ran detekt and targeted kotlinc/JUnit checks, and CI ran the full suite.

(This was put together with help from an AI coding assistant.)

@github-actions github-actions Bot removed the needs author feedback Further information required from the issue/PR author label Nov 26, 2026
@fractalwrench
fractalwrench requested a balanced review from Copilot November 27, 2026 09:31

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.

🔵 Needs a closer look

Changing the public Failure singleton into an open class requires maintainer review of JS/native binary compatibility and exhaustive Kotlin when-expression source compatibility, despite the retained JVM/Android INSTANCE bridge.

2 open issues
1 resolved since last review

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 ea9e18e into open-telemetry:main Nov 27, 2026
16 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.

Shutdown/ForceFlush results can't distinguish a timeout from a failure

3 participants