Skip to content

Commit

Permalink
Fix: `v1TraceToOtelTrace
Browse files Browse the repository at this point in the history
- upgrade test
- improve function structure

Signed-off-by: Emmanuel Emonueje Ebenezer <[email protected]>
  • Loading branch information
ekefan committed Dec 29, 2024
1 parent 6e0eeac commit 6c38cd2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
6 changes: 3 additions & 3 deletions storage_v2/v1adapter/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func V1TracesFromSeq2(otelSeq iter.Seq2[[]ptrace.Traces, error]) ([]*model.Trace
return jaegerTraces, nil
}

// Returns
// V1TraceToOtelTrace converts v1 traces (*model.Trace) to Otel traces (ptrace.Traces)
func V1TraceToOtelTrace(jTrace *model.Trace) ptrace.Traces {
otelTraces := V1BatchesToTraces(createBatchesFromModelTrace(jTrace))
return otelTraces
batches := createBatchesFromModelTrace(jTrace)
return V1BatchesToTraces(batches)
}

func createBatchesFromModelTrace(jTrace *model.Trace) []*model.Batch {
Expand Down
26 changes: 0 additions & 26 deletions storage_v2/v1adapter/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,36 +270,10 @@ func TestV1TraceToOtelTrace_ReturnsExptectedOtelTrace(t *testing.T) {
},
},
}
expectedTrace := ptrace.NewTraces()

for _, jspan := range jTrace.Spans {
resource := expectedTrace.ResourceSpans().AppendEmpty()
resource.Resource().Attributes().PutStr("service.name", jspan.Process.ServiceName)
eSpan := resource.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
eSpan.SetName(jspan.OperationName)
eSpan.SetSpanID(jspan.SpanID.ToOTELSpanID())
eSpan.SetTraceID(jspan.TraceID.ToOTELTraceID())
}

actualTrace := V1TraceToOtelTrace(jTrace)

require.NotEmpty(t, actualTrace)
require.Equal(t, 2, actualTrace.ResourceSpans().Len())
for i := range [2]int{} {
aServiceName, _ := actualTrace.ResourceSpans().At(i).Resource().Attributes().Get("service.name")
eServiceName, _ := expectedTrace.ResourceSpans().At(i).Resource().Attributes().Get("service.name")
require.Equal(t, aServiceName, eServiceName)

aSpans := actualTrace.ResourceSpans().At(i).ScopeSpans().At(0).Spans()
eSpans := expectedTrace.ResourceSpans().At(i).ScopeSpans().At(0).Spans()
require.Equal(t, aSpans.Len(), eSpans.Len())

aSpan := aSpans.At(0)
eSpan := eSpans.At(0)
require.Equal(t, eSpan.Name(), aSpan.Name())
require.Equal(t, eSpan.TraceID(), aSpan.TraceID())
require.Equal(t, eSpan.SpanID(), aSpan.SpanID())
}
}

func TestV1TraceToOtelTrace_ReturnEmptyOtelTrace(t *testing.T) {
Expand Down

0 comments on commit 6c38cd2

Please sign in to comment.