MCPcopy
hub / github.com/grafana/tempo / findParentNodeInMap

Function findParentNodeInMap

tempodb/encoding/vparquet4/nested_set_model.go:151–180  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
151func 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}

Calls 2

SpanIDToUint64Function · 0.92
IsRootMethod · 0.45

Tested by

no test coverage detected