()
| 68 | } |
| 69 | |
| 70 | func (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. |
no test coverage detected