Skip to content

Commit

Permalink
sdk/log: Fix BenchmarkLoggerNewRecord to not drop attributes (#5407)
Browse files Browse the repository at this point in the history
Leftover after
#5230

We want to have the benchmarks working with 5+ attributes as this is
when allocations kick in.

Before changes:
```
BenchmarkLoggerNewRecord/5_attributes-16         	 4016042	       309.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggerNewRecord/10_attributes-16        	 2150197	       543.4 ns/op	       0 B/op	       0 allocs/op
```

After changes:
```
BenchmarkLoggerNewRecord/5_attributes-16         	 3779966	       311.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggerNewRecord/10_attributes-16        	 1000000	      1314 ns/op	     610 B/op	       4 allocs/op
```
  • Loading branch information
pellared committed May 24, 2024
1 parent 55ec752 commit bd24d54
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sdk/log/logger_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/sdk/instrumentation"
Expand All @@ -24,18 +24,25 @@ func BenchmarkLoggerNewRecord(b *testing.B) {
r.SetSeverity(log.SeverityInfo)
r.SetSeverityText("testing text")

attrs5 := []log.KeyValue{
r.AddAttributes(
log.String("k1", "str"),
log.Float64("k2", 1.0),
log.Int("k3", 2),
log.Bool("k4", true),
log.Bytes("k5", []byte{1}),
}
r.AddAttributes(attrs5...)
)

r10 := r
r10.AddAttributes(attrs5...)
assert.Equal(b, 10, r10.AttributesLen())
r10.AddAttributes(
log.String("k6", "str"),
log.Float64("k7", 1.0),
log.Int("k8", 2),
log.Bool("k9", true),
log.Bytes("k10", []byte{1}),
)

require.Equal(b, 5, r.AttributesLen())
require.Equal(b, 10, r10.AttributesLen())

b.Run("5 attributes", func(b *testing.B) {
b.ReportAllocs()
Expand Down

0 comments on commit bd24d54

Please sign in to comment.