Repository navigation
RHINENG-28312: Fix ingestion span parenting and listener timing #2374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MichaelMraka
merged 3 commits into
RedHatInsights:master
from
rodrigonull:fix/evaluator-span-parenting
Oct 29, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package telemetry | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "go.opentelemetry.io/otel/attribute" | ||
| sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
| "go.opentelemetry.io/otel/trace" | ||
| ) | ||
|
|
||
| // RecordBufferWait records one host's additional wait before publication. Time | ||
| // already covered by its local processing span is excluded. A still-running | ||
| // processing span (including a synchronous flush) therefore gets a zero-duration | ||
| // 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) | ||
| if !ok { | ||
| // Remote and unsampled spans cannot supply a local processing end time. | ||
| return | ||
| } | ||
| start := enqueuedAt | ||
| processedAt := processing.EndTime() | ||
| if processedAt.IsZero() || processedAt.After(publishAt) { | ||
| start = publishAt | ||
| } else if processedAt.After(start) { | ||
| start = processedAt | ||
| } | ||
|
|
||
| ctx := trace.ContextWithSpan(context.Background(), parent) | ||
| _, span := Tracer().Start(ctx, "buffer wait "+topic, | ||
| trace.WithTimestamp(start), | ||
| trace.WithSpanKind(trace.SpanKindInternal), | ||
| trace.WithAttributes(attribute.String("messaging.destination.name", topic)), | ||
| ) | ||
| span.End(trace.WithTimestamp(publishAt)) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package telemetry | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "go.opentelemetry.io/otel/trace" | ||
| ) | ||
|
|
||
| func TestRecordBufferWaitExcludesProcessingOverlap(t *testing.T) { | ||
| const topic = "evaluation" | ||
| enqueuedAt := time.Now() | ||
| publishAt := enqueuedAt.Add(time.Second) | ||
| cases := []struct { | ||
| name string | ||
| processedAt time.Time | ||
| wantStart time.Time | ||
| }{ | ||
| {"already processed", enqueuedAt.Add(-time.Millisecond), enqueuedAt}, | ||
| {"partial overlap", enqueuedAt.Add(100 * time.Millisecond), enqueuedAt.Add(100 * time.Millisecond)}, | ||
| {"still processing", time.Time{}, publishAt}, | ||
| {"ended during publish", publishAt.Add(time.Millisecond), publishAt}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| exp := setupKafkaTest(t) | ||
| _, parent := Tracer().Start(t.Context(), "processing", trace.WithTimestamp(enqueuedAt.Add(-time.Second))) | ||
| SetRHAttributes(parent, "buffer-org", "buffer-request") | ||
| if !tc.processedAt.IsZero() { | ||
| parent.End(trace.WithTimestamp(tc.processedAt)) | ||
| } | ||
| RecordBufferWait(parent, topic, enqueuedAt, publishAt) | ||
| if tc.processedAt.IsZero() { | ||
| assert.True(t, parent.IsRecording()) | ||
| } else { | ||
| assert.False(t, parent.IsRecording()) | ||
| } | ||
| spans := exp.GetSpans() | ||
| require.NotEmpty(t, spans) | ||
| wait := spans[len(spans)-1] | ||
| assert.Equal(t, "buffer wait "+topic, wait.Name) | ||
| assert.Equal(t, tc.wantStart, wait.StartTime) | ||
| assert.Equal(t, publishAt, wait.EndTime) | ||
| assert.Equal(t, parent.SpanContext().SpanID(), wait.Parent.SpanID()) | ||
| assert.Equal(t, parent.SpanContext().TraceID(), wait.SpanContext.TraceID()) | ||
| assert.Equal(t, trace.SpanKindInternal, wait.SpanKind) | ||
| assert.Equal(t, topic, attr(wait, "messaging.destination.name")) | ||
| assert.Equal(t, "buffer-org", attr(wait, "rh.org_id")) | ||
| assert.Equal(t, "buffer-request", attr(wait, "rh.request_id")) | ||
| parent.End() | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRecordBufferWaitDisabledOrMissingLocalSpan(t *testing.T) { | ||
| exp := setupKafkaTest(t) | ||
| now := time.Now() | ||
| RecordBufferWait(trace.SpanFromContext(context.Background()), "evaluation", now, now) | ||
| remote := ContextFromTraceparent("00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-01") | ||
| RecordBufferWait(trace.SpanFromContext(remote), "evaluation", now, now) | ||
| assert.Empty(t, exp.GetSpans()) | ||
|
|
||
| _, parent := Tracer().Start(t.Context(), "processing") | ||
| t.Setenv("OTEL_MQ_ENABLED", "false") | ||
| RecordBufferWait(parent, "evaluation", now, now) | ||
| assert.Empty(t, exp.GetSpans()) | ||
| assert.True(t, parent.IsRecording()) | ||
| parent.End() | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.