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)
| 168 | // contain client/server span pairs with identical span IDs. In those cases the span kind is used to find |
| 169 | // the matching parent span. |
| 170 | func findParentNodeInMap(nodesByID map[uint64][]*spanNode, node *spanNode) *spanNode { |
| 171 | if node.span.IsRoot() { |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | parentID := util.SpanIDToUint64(node.span.ParentSpanID) |
| 176 | nodes := nodesByID[parentID] |
| 177 | |
| 178 | switch len(nodes) { |
| 179 | case 0: |
| 180 | return nil |
| 181 | case 1: |
| 182 | return nodes[0] |
| 183 | case 2: |
| 184 | // handle client/server spans with the same span ID |
| 185 | kindWant := int(v1.Span_SPAN_KIND_SERVER) |
| 186 | if node.span.Kind == int(v1.Span_SPAN_KIND_SERVER) { |
| 187 | kindWant = int(v1.Span_SPAN_KIND_CLIENT) |
| 188 | } |
| 189 | |
| 190 | if nodes[0].span.Kind == kindWant { |
| 191 | return nodes[0] |
| 192 | } |
| 193 | if nodes[1].span.Kind == kindWant { |
| 194 | return nodes[1] |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return nil |
| 199 | } |
no test coverage detected