Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #183 from signalfx/jaegerparentid
Browse files Browse the repository at this point in the history
Use span references to determine parentSpanId if not already set
  • Loading branch information
sstewart-signalfx authored Jan 17, 2019
2 parents 8d9d82d + 11400a4 commit 6835157
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
16 changes: 16 additions & 0 deletions protocol/signalfx/trace_jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func convertJaegerSpan(tSpan *jThrift.Span, tProcess *jThrift.Process) *trace.Sp
var ptrParentID *string
if tSpan.ParentSpanId != 0 {
ptrParentID = pointer.String(padID(strconv.FormatUint(uint64(tSpan.ParentSpanId), 16)))
} else {
refs := tSpan.GetReferences()
if len(refs) > 0 {
ptrParentID = pointer.String(padID(strconv.FormatUint(uint64(getPreferredParentRef(refs)), 16)))
}
}

localEndpoint := &trace.Endpoint{
Expand Down Expand Up @@ -149,6 +154,17 @@ func convertJaegerSpan(tSpan *jThrift.Span, tProcess *jThrift.Process) *trace.Sp
return span
}

func getPreferredParentRef(refs []*jThrift.SpanRef) int64 {
preferredRef := refs[0]
for i := range refs {
if jThrift.SpanRefType_CHILD_OF == refs[i].RefType && jThrift.SpanRefType_CHILD_OF != preferredRef.RefType {
preferredRef = refs[i]
break
}
}
return preferredRef.SpanId
}

func convertJaegerLogs(logs []*jThrift.Log) []*trace.Annotation {
annotations := make([]*trace.Annotation, 0, len(logs))
for i := range logs {
Expand Down
55 changes: 55 additions & 0 deletions protocol/signalfx/trace_jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ const jaegerBatchJSON = `
}
]
},
{
"traceIdLow": 5951113872249657919,
"spanId": 27532398882098234,
"operationName": "post",
"startTime": 1485467191639875,
"flags": 2,
"duration": 22938,
"tags": [
{
"key": "span.kind",
"vType": "STRING",
"vStr": "producer"
},
{
"key": "peer.ipv6",
"vType": "STRING",
"vStr": "::1"
}
],
"references": [
{
"refType": "FOLLOWS_FROM",
"traceIdLow": 5951113872249657919,
"spanId": 6866148
},
{
"refType": "CHILD_OF",
"traceIdLow": 5951113872249657919,
"spanId": 6866147
}
]
},
{
"traceIdLow": 5951113872249657919,
"spanId": 27532398882098234,
Expand Down Expand Up @@ -322,6 +354,29 @@ func TestJaegerTraceDecoder(t *testing.T) {
"jaeger.version": "Python-3.1.0",
},
},
{
TraceID: "52969a8955571a3f",
ParentID: pointer.String("000000000068c4e3"),
ID: "0061d092272e8c3a",
Name: pointer.String("post"),
Kind: &ProducerKind,
LocalEndpoint: &trace.Endpoint{
ServiceName: pointer.String("api"),
Ipv4: pointer.String("10.53.69.61"),
},
RemoteEndpoint: &trace.Endpoint{
Ipv6: pointer.String("::1"),
},
Timestamp: pointer.Int64(1485467191639875),
Duration: pointer.Int64(22938),
Debug: pointer.Bool(true),
Shared: nil,
Annotations: []*trace.Annotation{},
Tags: map[string]string{
"hostname": "api246-sjc1",
"jaeger.version": "Python-3.1.0",
},
},
{
TraceID: "52969a8955571a3f",
ParentID: pointer.String("000000000068c4e3"),
Expand Down

0 comments on commit 6835157

Please sign in to comment.