CAMEL-23993: Fix flaky SpanPropagationUpstreamTest - add tie-breaking to SpanComparator#24591
Open
gnodet wants to merge 1 commit into
Open
CAMEL-23993: Fix flaky SpanPropagationUpstreamTest - add tie-breaking to SpanComparator#24591gnodet wants to merge 1 commit into
gnodet wants to merge 1 commit into
Conversation
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Contributor
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 12 tested, 29 compile-only — current: 13 all testedMaveniverse Scalpel detected 41 affected modules (current approach: 13).
|
… to SpanComparator SpanComparator sorted spans by startEpochNanos only. When multiple spans started at the same nanosecond (common on fast systems), Java's TimSort preserved InMemorySpanExporter insertion order which is end-order (inner spans first), the reverse of the creation order tests expect. Add endEpochNanos descending as a secondary sort key. Parent spans always end after their children, so this deterministically places parents first when start times tie, matching the expected hierarchy order. Also fixes an integer overflow bug in the mock-based comparators (camel-telemetry, camel-telemetry-dev) that used (int)(longA - longB) instead of Long.compare(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f3333d0 to
dc4087d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Claude Code on behalf of gnodet
Fix flaky
SpanPropagationUpstreamTestwhich was failing ~20% of the time (35/175 runs on Develocity).Root cause:
SpanComparatorsorts spans bystartEpochNanosonly. When timestamps tie (same nanosecond — common on fast hardware), Java'sTimSort(stable sort) preservesInMemorySpanExporterinsertion order, which is end order (innermost/leaf spans end first). This reverses sibling spans relative to the creation order the tests expect when accessing spans by positional index (spans.get(0),spans.get(1), etc.).Fix: Add a secondary sort key —
endEpochNanosdescending — to break ties deterministically. Parent spans always end after their children in OpenTelemetry's trace hierarchy, so sorting by end time descending naturally puts parents before children when start times tie. This matches what tests assume.Additionally fixes a potential integer overflow bug in
camel-telemetryandcamel-telemetry-devcomparators that used(int)(longA - longB)instead ofLong.compare(longA, longB).Changes
All 4
SpanComparatorimplementations updated:components/camel-micrometer-observability/.../CamelOpenTelemetryExtension.javacomponents/camel-opentelemetry2/.../CamelOpenTelemetryExtension.javacomponents/camel-telemetry/.../MockTrace.javacomponents/camel-telemetry-dev/.../DevTrace.javaValidation
Test plan
SpanPropagationUpstreamTestpasses in all 4 modulescamel-telemetry(155 tests),camel-telemetry-dev(13 tests)🤖 Generated with Claude Code