Skip to content

Commit

Permalink
extend trace start benchmark to include links and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jun 27, 2024
1 parent fe79da4 commit 8925ac4
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2112,17 +2112,48 @@ func BenchmarkTraceStart(b *testing.B) {
tracer := NewTracerProvider().Tracer("")
ctx := trace.ContextWithSpanContext(context.Background(), trace.SpanContext{})

spans := make([]trace.Span, b.N)
b.ReportAllocs()
b.ResetTimer()
l1 := trace.Link{SpanContext: trace.SpanContext{}, Attributes: []attribute.KeyValue{}}
l2 := trace.Link{SpanContext: trace.SpanContext{}, Attributes: []attribute.KeyValue{}}

for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "")
spans[i] = span
}
links := []trace.Link{l1, l2}

b.StopTimer()
for i := 0; i < b.N; i++ {
spans[i].End()
for _, tt := range []struct {
name string
options []trace.SpanStartOption
}{
{
name: "with a simple span",
},
{
name: "with several links",
options: []trace.SpanStartOption{
trace.WithLinks(links...),
},
},
{
name: "with attributes",
options: []trace.SpanStartOption{
trace.WithAttributes(
attribute.String("key1", "value1"),
attribute.String("key2", "value2"),
),
},
},
} {
b.Run(tt.name, func(b *testing.B) {
spans := make([]trace.Span, b.N)
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "", tt.options...)
spans[i] = span
}

b.StopTimer()
for i := 0; i < b.N; i++ {
spans[i].End()
}
})
}
}

0 comments on commit 8925ac4

Please sign in to comment.