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

Method dedupeSpanIDs

modules/frontend/combiner/trace_by_id_deduper.go:70–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68}
69
70func (s *spanIDDeduper) dedupeSpanIDs() {
71 oldToNewSpanIDs := make(map[uint64]uint64)
72 for _, batch := range s.trace.ResourceSpans {
73 for _, ils := range batch.ScopeSpans {
74 for _, span := range ils.Spans {
75 id := binary.BigEndian.Uint64(span.SpanId)
76 // only replace span IDs for server-side spans that share the ID with something else
77 if span.GetKind() == v1.Span_SPAN_KIND_SERVER && s.isSharedWithClientSpan(id) {
78 newID, err := s.makeUniqueSpanID()
79 if err != nil {
80 // ignore this error condition where we have more than 2^64 unique span IDs
81 continue
82 }
83 oldToNewSpanIDs[id] = newID
84 if len(span.ParentSpanId) == 0 {
85 span.ParentSpanId = make([]byte, 8)
86 }
87 binary.BigEndian.PutUint64(span.ParentSpanId, id) // previously shared ID is the new parent
88 binary.BigEndian.PutUint64(span.SpanId, newID)
89 }
90 }
91 }
92 }
93 s.swapParentIDs(oldToNewSpanIDs)
94}
95
96// swapParentIDs corrects ParentSpanID of all spans that are children of the server
97// spans whose IDs we deduped.

Callers 1

dedupeMethod · 0.95

Calls 4

makeUniqueSpanIDMethod · 0.95
swapParentIDsMethod · 0.95
GetKindMethod · 0.80

Tested by

no test coverage detected