Skip to content

Commit

Permalink
Add evictedqueue copy method
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed May 29, 2024
1 parent 8ce5b48 commit 266fa7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
6 changes: 6 additions & 0 deletions sdk/trace/evictedqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package trace // import "go.opentelemetry.io/otel/sdk/trace"

import (
"fmt"
"slices"
"sync"

"go.opentelemetry.io/otel/internal/global"
Expand Down Expand Up @@ -46,3 +47,8 @@ func (eq *evictedQueue[T]) add(value T) {
}
eq.queue = append(eq.queue, value)
}

// copy returns a copy of the evictedQueue.
func (eq *evictedQueue[T]) copy() []T {
return slices.Clone(eq.queue)
}
24 changes: 4 additions & 20 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func (s *recordingSpan) Links() []Link {
if len(s.links.queue) == 0 {
return []Link{}
}
return s.interfaceArrayToLinksArray()
return s.links.copy()
}

// Events returns the events of this span.
Expand All @@ -613,7 +613,7 @@ func (s *recordingSpan) Events() []Event {
if len(s.events.queue) == 0 {
return []Event{}
}
return s.interfaceArrayToEventArray()
return s.events.copy()
}

// Status returns the status of this span.
Expand Down Expand Up @@ -735,32 +735,16 @@ func (s *recordingSpan) snapshot() ReadOnlySpan {
}
sd.droppedAttributeCount = s.droppedAttributes
if len(s.events.queue) > 0 {
sd.events = s.interfaceArrayToEventArray()
sd.events = s.events.copy()
sd.droppedEventCount = s.events.droppedCount
}
if len(s.links.queue) > 0 {
sd.links = s.interfaceArrayToLinksArray()
sd.links = s.links.copy()
sd.droppedLinkCount = s.links.droppedCount
}
return &sd
}

func (s *recordingSpan) interfaceArrayToLinksArray() []Link {
linkArr := make([]Link, 0)
for _, value := range s.links.queue {
linkArr = append(linkArr, value)
}
return linkArr
}

func (s *recordingSpan) interfaceArrayToEventArray() []Event {
eventArr := make([]Event, 0)
for _, value := range s.events.queue {
eventArr = append(eventArr, value)
}
return eventArr
}

func (s *recordingSpan) addChild() {
if !s.IsRecording() {
return
Expand Down

0 comments on commit 266fa7b

Please sign in to comment.