Skip to content

Commit

Permalink
Implement Skeleton For Trace Aggregator
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Dec 24, 2024
1 parent 5b1c76b commit 82bf495
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/jptrace/aggregator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jptrace

import (
"iter"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
)

func AggregateTraces(tracesSeq iter.Seq[[]ptrace.Traces]) iter.Seq[ptrace.Traces] {
return func(yield func(trace ptrace.Traces) bool) {
currentTrace := ptrace.NewTraces()
currentTraceID := pcommon.NewTraceIDEmpty()

tracesSeq(func(traces []ptrace.Traces) bool {
for _, trace := range traces {
resources := trace.ResourceSpans()
// TODO: add non-empty requirement to contract
traceID := resources.At(0).ScopeSpans().At(0).Spans().At(0).TraceID()
if currentTraceID == pcommon.NewTraceIDEmpty() {
currentTrace = trace
currentTraceID = traceID
} else if currentTraceID == traceID {
// TODO: merge traces
} else {
if !yield(currentTrace) {
return false
}
currentTrace = ptrace.NewTraces()
currentTraceID = pcommon.NewTraceIDEmpty()

Check warning on line 30 in internal/jptrace/aggregator.go

View check run for this annotation

Codecov / codecov/patch

internal/jptrace/aggregator.go#L10-L30

Added lines #L10 - L30 were not covered by tests
}
}
return true

Check warning on line 33 in internal/jptrace/aggregator.go

View check run for this annotation

Codecov / codecov/patch

internal/jptrace/aggregator.go#L33

Added line #L33 was not covered by tests
})

if currentTraceID != pcommon.NewTraceIDEmpty() {
yield(currentTrace)
}

Check warning on line 38 in internal/jptrace/aggregator.go

View check run for this annotation

Codecov / codecov/patch

internal/jptrace/aggregator.go#L36-L38

Added lines #L36 - L38 were not covered by tests
}
}

0 comments on commit 82bf495

Please sign in to comment.