Skip to content

RHINENG-28312: Fix ingestion span parenting and listener timing - #2374

Merged
MichaelMraka merged 3 commits into
RedHatInsights:masterfrom
rodrigonull:fix/evaluator-span-parenting
Oct 29, 2026
Merged

MichaelMraka merged 3 commits into
RedHatInsights:masterfrom
rodrigonull:fix/evaluator-span-parenting

Conversation

@rodrigonull

@rodrigonull rodrigonull commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Jira

RHINENG-28312

What

Correct evaluation span parenting and listener producer spans. Add per-host buffer-wait spans to capture delays between listener processing and evaluation publication.

Why

Evaluation spans currently appear outside their consumer span, producer spans can report the wrong destination and asynchronous buffer waits are missing from processing durations.

These changes improve trace readability and provide more accurate timing data for ingestion metrics.

How

  • Nest evaluation spans under the consumer when they share a trace. For mixed-trace batches, preserve each host’s original trace and link to the consumer.
  • Use the actual evaluation destination and end producer spans immediately after evaluation publishing.
  • Record buffer wait per host, excluding time already covered by listener processing. Record zero additional wait when processing overlaps publication, including synchronous flushes.
  • Skip empty flushes and release buffered span references after publishing.

Testing

Passed in the build container:

  • Telemetry suite with the race detector.
  • Listener buffer tests covering both destinations, publish failures, timer flushes, and synchronous overlap.
  • Scoped golangci-lint checks: zero issues.

Summary by Sourcery

Improve ingestion tracing by correcting span relationships and capturing accurate per-host buffering delays.

New Features:

  • Add per-host buffer-wait telemetry spans to measure delays before buffered evaluation publication.

Bug Fixes:

  • Correct evaluation span parenting across same-trace and mixed-trace batches.
  • Ensure producer spans use the actual evaluation destination and end immediately after evaluation publication.
  • Prevent empty buffer flushes and release buffered trace references after publishing.

Enhancements:

  • Exclude listener processing time from buffer-wait measurements, including synchronous publication overlap.

Tests:

  • Add telemetry and event-buffer coverage for trace parenting, destinations, publish failures, timer flushes, and processing overlap.

Keep per-host evaluation spans under the active consumer when they
share a trace. This makes upload and user-evaluation work appear
inside the processing span that actually contains it.

For mixed-trace batches, preserve each host's original trace and
link its evaluation to the active consumer. Cover both evaluation
labels, mixed batches, and missing or invalid parent contexts.

Assisted-by: GPT-6
Use each buffer's destination for its producer span and end the
span immediately after evaluation publishing. Payload tracking
must not inflate the evaluation publish duration.

Record one buffer-wait span per traced host for time between
listener processing and publication. Exclude processing overlap
and retain zero-duration observations for synchronous flushes so
span metrics count hosts without counting the same time twice.

Skip empty flushes and release buffered span references after
publishing. Add timing and failure regression coverage and document
the metric boundaries.

Assisted-by: GPT-6
Revert the listener buffer tracing section as requested, keeping
the tracing fixes and regression tests in this change set.

Assisted-by: GPT-6
@rodrigonull
rodrigonull requested a review from a team as a code owner October 27, 2026 13:55
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR improves ingestion tracing by fixing evaluation-to-consumer parenting across trace scenarios, adding per-host buffer-wait spans that exclude overlapping processing, and tightening buffered producer instrumentation around destination selection, publish completion, empty flushes, and reference cleanup.

File-Level Changes

Change Details Files
Correct evaluation span ancestry for same-trace and mixed-trace batches.
  • Parent same-trace evaluation spans under the consumer span.
  • Preserve original trace parents for mixed-trace items and add consumer links.
  • Add coverage for fallback, same-trace, and mixed-trace parenting behavior.
base/telemetry/kafka.go
base/telemetry/kafka_test.go
Add per-host buffer-wait telemetry that measures only time not covered by processing.
  • Track each buffered host’s span and enqueue timestamp.
  • Create host-specific wait spans from processing completion or publication time through publication.
  • Handle unsampled/remote spans and disabled messaging telemetry without emitting waits.
base/telemetry/buffer.go
base/telemetry/buffer_test.go
listener/event_buffers.go
listener/event_buffers_test.go
Make buffered evaluation publishing use the configured destination and precise producer-span lifecycle.
  • Store the evaluation topic per buffer and use it for producer context and attributes.
  • End the producer span immediately after evaluation publishing, including failures, before payload tracking.
  • Skip empty flushes and clear buffered span references after publication.
listener/event_buffers.go
listener/listener.go
listener/event_buffers_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="base/telemetry/buffer.go" line_range="23" />
<code_context>
+// observation, keeping span-metric counts representative of all buffered hosts.
+func RecordBufferWait(parent trace.Span, topic string, enqueuedAt, publishAt time.Time) {
+	if !MQEnabled() {
+		return
+	}
+	processing, ok := parent.(sdktrace.ReadOnlySpan)
</code_context>
<issue_to_address>
**Sampled-out hosts lose wait observations**

When `OTEL_SAMPLING_RATE` is below 1 and the host's trace is sampled out, the non-recording SDK span does not satisfy `sdktrace.ReadOnlySpan`, so `RecordBufferWait` returns without creating an observation; when trace sampling is below 100%, span-derived buffer-wait counts omit those hosts.

Use an observation mechanism that is independent of trace sampling for host counts, or otherwise ensure buffer-wait observations survive parent-based sampling.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: base/telemetry/buffer.go:23


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread base/telemetry/buffer.go Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.13%. Comparing base (2912769) to head (424e271).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2374      +/-   ##
==========================================
+ Coverage   59.89%   60.13%   +0.23%     
==========================================
  Files         157      158       +1     
  Lines       10119    10153      +34     
==========================================
+ Hits         6061     6105      +44     
+ Misses       3431     3423       -8     
+ Partials      627      625       -2     
Flag Coverage Δ
unittests 60.13% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@MichaelMraka
MichaelMraka merged commit 6259d80 into RedHatInsights:master Oct 29, 2026
8 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.

3 participants