Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk/log: Change BenchmarkLoggerNewRecord to BenchmarkLoggerEmit #6315

Merged
merged 5 commits into from
Feb 14, 2025
Merged
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
23 changes: 13 additions & 10 deletions sdk/log/logger_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/sdk/instrumentation"
)

func BenchmarkLoggerNewRecord(b *testing.B) {
logger := newLogger(NewLoggerProvider(), instrumentation.Scope{})
func BenchmarkLoggerEmit(b *testing.B) {
logger := newTestLogger(b)

r := log.Record{}
r.SetTimestamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC))
Expand Down Expand Up @@ -48,7 +47,7 @@ func BenchmarkLoggerNewRecord(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.newRecord(context.Background(), r)
logger.Emit(context.Background(), r)
}
})
})
Expand All @@ -57,18 +56,14 @@ func BenchmarkLoggerNewRecord(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.newRecord(context.Background(), r10)
logger.Emit(context.Background(), r10)
}
})
})
}

func BenchmarkLoggerEnabled(b *testing.B) {
provider := NewLoggerProvider(
WithProcessor(newFltrProcessor("0", false)),
WithProcessor(newFltrProcessor("1", true)),
)
logger := provider.Logger(b.Name())
logger := newTestLogger(b)
ctx := context.Background()
param := log.EnabledParameters{Severity: log.SeverityDebug}
var enabled bool
Expand All @@ -82,3 +77,11 @@ func BenchmarkLoggerEnabled(b *testing.B) {

_ = enabled
}

func newTestLogger(t testing.TB) log.Logger {
provider := NewLoggerProvider(
WithProcessor(newFltrProcessor("0", false)),
WithProcessor(newFltrProcessor("1", true)),
)
return provider.Logger(t.Name())
}
Loading