fix: include orphan traces (#4)

This commit is contained in:
Marc 2023-04-26 23:02:59 -04:00 committed by GitHub
parent e6cb20bc83
commit 32c7cb85df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

30
main.go
View file

@ -38,9 +38,9 @@ type Trace struct {
} }
type TraceData struct { type TraceData struct {
Trace Trace `json:"trace"` Trace Trace `json:"trace"`
Orphaned []Span `json:"orphaned"` Orphaned []Trace `json:"orphaned"`
IsTruncated bool `json:"is_truncated"` IsTruncated bool `json:"is_truncated"`
} }
type Config struct { type Config struct {
@ -94,16 +94,24 @@ func buildSpanIndexes(fullTrace TraceData) (map[string]Span, map[string][]string
spansById := map[string]Span{} spansById := map[string]Span{}
spanIdsByResourceName := map[string][]string{} spanIdsByResourceName := map[string][]string{}
for key, value := range fullTrace.Trace.Spans { tracesToProcess := []Trace{fullTrace.Trace}
resourceName := value.Resource
spansById[key] = value
spanList, ok := spanIdsByResourceName[resourceName] if fullTrace.Orphaned != nil {
tracesToProcess = append(tracesToProcess, fullTrace.Orphaned...)
}
if !ok { for _, trace := range tracesToProcess {
spanIdsByResourceName[resourceName] = []string{key} for key, value := range trace.Spans {
} else { resourceName := value.Resource
spanIdsByResourceName[resourceName] = append(spanList, key) spansById[key] = value
spanList, ok := spanIdsByResourceName[resourceName]
if !ok {
spanIdsByResourceName[resourceName] = []string{key}
} else {
spanIdsByResourceName[resourceName] = append(spanList, key)
}
} }
} }