You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Log warning when a trace attribute/event/link is discarded due to limits (#5434)
Fix #5343 - Update the `evictionQueue` to log when it drops a value - Update the `evictionQueue` to be declared over an `[T any]` parameter so it knows what to log when it is dropping a value and to reduce the `interface{}` allocation - Add a `clone` method to replace the now unneeded `interfaceArrayTo*Array` functions. - Update the `recordingSpan` to log once that is dropped an attribute when limits are reached.
This commit is contained in:
@@ -6,13 +6,15 @@ package trace
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
q := newEvictedQueue(3)
|
||||
q := newEvictedQueue[string](3)
|
||||
q.add("value1")
|
||||
q.add("value2")
|
||||
if wantLen, gotLen := 2, len(q.queue); wantLen != gotLen {
|
||||
@@ -20,20 +22,31 @@ func TestAdd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (eq *evictedQueue) queueToArray() []string {
|
||||
arr := make([]string, 0)
|
||||
for _, value := range eq.queue {
|
||||
arr = append(arr, value.(string))
|
||||
}
|
||||
return arr
|
||||
func TestCopy(t *testing.T) {
|
||||
q := newEvictedQueue[string](3)
|
||||
q.add("value1")
|
||||
cp := q.copy()
|
||||
|
||||
q.add("value2")
|
||||
assert.Equal(t, []string{"value1"}, cp, "queue update modified copy")
|
||||
|
||||
cp[0] = "value0"
|
||||
assert.Equal(t, "value1", q.queue[0], "copy update modified queue")
|
||||
}
|
||||
|
||||
func TestDropCount(t *testing.T) {
|
||||
q := newEvictedQueue(3)
|
||||
q := newEvictedQueue[string](3)
|
||||
var called bool
|
||||
q.logDropped = func() { called = true }
|
||||
|
||||
q.add("value1")
|
||||
assert.False(t, called, `"value1" logged as dropped`)
|
||||
q.add("value2")
|
||||
assert.False(t, called, `"value2" logged as dropped`)
|
||||
q.add("value3")
|
||||
assert.False(t, called, `"value3" logged as dropped`)
|
||||
q.add("value1")
|
||||
assert.True(t, called, `"value2" not logged as dropped`)
|
||||
q.add("value4")
|
||||
if wantLen, gotLen := 3, len(q.queue); wantLen != gotLen {
|
||||
t.Errorf("got queue length %d want %d", gotLen, wantLen)
|
||||
@@ -42,7 +55,7 @@ func TestDropCount(t *testing.T) {
|
||||
t.Errorf("got drop count %d want %d", gotDropCount, wantDropCount)
|
||||
}
|
||||
wantArr := []string{"value3", "value1", "value4"}
|
||||
gotArr := q.queueToArray()
|
||||
gotArr := q.copy()
|
||||
|
||||
if wantLen, gotLen := len(wantArr), len(gotArr); gotLen != wantLen {
|
||||
t.Errorf("got array len %d want %d", gotLen, wantLen)
|
||||
|
||||
Reference in New Issue
Block a user