findParentNodeInMap finds the tree node containing the parent span for another node. zipkin traces can contain client/server span pairs with identical span IDs. In those cases the span kind is used to find the matching parent span.
(nodesByID map[uint64][]*spanNode, node *spanNode)
| 149 | // contain client/server span pairs with identical span IDs. In those cases the span kind is used to find |
| 150 | // the matching parent span. |
| 151 | func findParentNodeInMap(nodesByID map[uint64][]*spanNode, node *spanNode) *spanNode { |
| 152 | if node.span.IsRoot() { |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | parentID := util.SpanIDToUint64(node.span.ParentSpanID) |
| 157 | nodes := nodesByID[parentID] |
| 158 | |
| 159 | switch len(nodes) { |
| 160 | case 0: |
| 161 | return nil |
| 162 | case 1: |
| 163 | return nodes[0] |
| 164 | case 2: |
| 165 | // handle client/server spans with the same span ID |
| 166 | kindWant := int(v1.Span_SPAN_KIND_SERVER) |
| 167 | if node.span.Kind == int(v1.Span_SPAN_KIND_SERVER) { |
| 168 | kindWant = int(v1.Span_SPAN_KIND_CLIENT) |
| 169 | } |
| 170 | |
| 171 | if nodes[0].span.Kind == kindWant { |
| 172 | return nodes[0] |
| 173 | } |
| 174 | if nodes[1].span.Kind == kindWant { |
| 175 | return nodes[1] |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return nil |
| 180 | } |
no test coverage detected