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

Function findParentNodeInMap

tempodb/encoding/vparquet3/nested_set_model.go:136–165  ·  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

134// contain client/server span pairs with identical span IDs. In those cases the span kind is used to find
135// the matching parent span.
136func findParentNodeInMap(nodesByID map[uint64][]*spanNode, node *spanNode) *spanNode {
137 if node.span.IsRoot() {
138 return nil
139 }
140
141 parentID := util.SpanIDToUint64(node.span.ParentSpanID)
142 nodes := nodesByID[parentID]
143
144 switch len(nodes) {
145 case 0:
146 return nil
147 case 1:
148 return nodes[0]
149 case 2:
150 // handle client/server spans with the same span ID
151 kindWant := int(v1.Span_SPAN_KIND_SERVER)
152 if node.span.Kind == int(v1.Span_SPAN_KIND_SERVER) {
153 kindWant = int(v1.Span_SPAN_KIND_CLIENT)
154 }
155
156 if nodes[0].span.Kind == kindWant {
157 return nodes[0]
158 }
159 if nodes[1].span.Kind == kindWant {
160 return nodes[1]
161 }
162 }
163
164 return nil
165}

Callers 1

Calls 2

SpanIDToUint64Function · 0.92
IsRootMethod · 0.45

Tested by

no test coverage detected