Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Translate jaeger ref to otel span link with meta attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Arunprasad Rajkumar <ar.arunprasad@gmail.com>
  • Loading branch information
arajkumar committed Oct 17, 2022
1 parent 7326873 commit d5a6eed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
46 changes: 30 additions & 16 deletions pkg/jaeger/store/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,34 @@ func addRefTypeAttributeToLinks(span *model.Span, links ptrace.SpanLinkSlice) {
// The reference to the parent span is stored directly as an attribute
// of the Span and not as a Link.
parentsSpanID := span.ParentSpanID()
otherParentsSpanIDs := map[model.SpanID]struct{}{}

// Since there are only 2 types of refereces, ChildOf and FollowsFrom, we
// keep track only of the former.
// Recreate SpanLinkSlice from Span References.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/c9e646b99610615730a845acc278b30bf49aa35f/pkg/translator/jaeger/jaegerproto_to_traces.go#L411-L427
spanLinks := ptrace.NewSpanLinkSlice()
spanLinks.EnsureCapacity(len(span.References))
for _, ref := range span.References {
if ref.RefType == model.ChildOf && ref.SpanID != parentsSpanID {
otherParentsSpanIDs[ref.SpanID] = struct{}{}
if ref.RefType == model.ChildOf && ref.SpanID == parentsSpanID {
continue
}
sl := spanLinks.AppendEmpty()
jSpanRefToInternal(ref, sl)
}
spanLinks.CopyTo(links)
}

for i := 0; i < links.Len(); i++ {
link := links.At(i)
spanID := spanIDToJaegerProto(link.SpanID())
func jSpanRefToInternal(ref model.SpanRef, link ptrace.SpanLink) {
link.SetTraceID(uInt64ToTraceID(ref.TraceID.High, ref.TraceID.Low))
link.SetSpanID(uInt64ToSpanID(uint64(ref.SpanID)))

// Everything that's not ChildOf will be set as FollowsFrom.
if _, ok := otherParentsSpanIDs[spanID]; ok {
link.Attributes().PutString(
conventions.AttributeOpentracingRefType,
conventions.AttributeOpentracingRefTypeChildOf,
)
continue
}
// Since there are only 2 types of refereces, ChildOf and FollowsFrom, we
// keep track only of the former.
// Everything that's not ChildOf will be set as FollowsFrom.
if ref.RefType == model.ChildOf {
link.Attributes().PutString(
conventions.AttributeOpentracingRefType,
conventions.AttributeOpentracingRefTypeChildOf,
)
} else {
link.Attributes().PutString(
conventions.AttributeOpentracingRefType,
conventions.AttributeOpentracingRefTypeFollowsFrom,
Expand Down Expand Up @@ -259,6 +265,14 @@ func getOtherParents(traces ptrace.Traces) map[model.SpanID][]int {
return otherParents
}

// UInt64ToTraceID converts the pair of uint64 representation of a TraceID to pcommon.TraceID.
func uInt64ToTraceID(high, low uint64) pcommon.TraceID {
traceID := [16]byte{}
binary.BigEndian.PutUint64(traceID[:8], high)
binary.BigEndian.PutUint64(traceID[8:], low)
return traceID
}

func uInt64ToSpanID(id uint64) pcommon.SpanID {
spanID := pcommon.SpanID{}
binary.BigEndian.PutUint64(spanID[:], id)
Expand Down
7 changes: 0 additions & 7 deletions pkg/tests/end_to_end_tests/jaeger_store_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ func TestJaegerStorageIntegration(t *testing.T) {
return nil
},
Refresh: func() error { return nil },
SkipList: []string{
// TODO: This test is failing even with the following fixes.
// https://github.com/timescale/promscale/pull/1681
// https://github.com/timescale/promscale/pull/1678
// Let's skip now and fix it in a follow-up PR.
"FindTraces/Tags_\\+_Operation_name$",
},
}
si.IntegrationTestAll(t.(*testing.T))
})
Expand Down

0 comments on commit d5a6eed

Please sign in to comment.