Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,17 @@ func newSpan(ctx context.Context, f *Func, args []interface{},
s.children.Iterate(func(child *Span) {
children = append(children, child)
})
s.children.Clear()
s.mtx.Unlock()
for _, child := range children {
child.orphan()

if s.parent != nil && !orphaned {
for _, child := range children {
s.parent.addChild(child)
}
} else {
for _, child := range children {
child.orphan()
}
}

if s.parent != nil {
Expand Down
17 changes: 15 additions & 2 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,31 @@ type Annotation struct {

func (s *Span) addChild(child *Span) {
s.mtx.Lock()
s.children.Add(child)
done := s.done
parent := s.parent
if !done {
s.children.Add(child)
}
s.mtx.Unlock()

if done {
child.orphan()
if parent == nil {
child.orphan()
} else {
parent.addChild(child)
}
}
}

func (s *Span) removeChild(child *Span) {
s.mtx.Lock()
parent := s.parent
s.children.Remove(child)
s.mtx.Unlock()

if parent != nil {
parent.removeChild(child)
}
}

func (s *Span) orphan() {
Expand Down
5 changes: 5 additions & 0 deletions spanbag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type spanBag struct {
rest map[*Span]int32
}

func (b *spanBag) Clear() {
b.first = nil
b.rest = nil
}

func (b *spanBag) Add(s *Span) {
if b.first == nil {
b.first = s
Expand Down