1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-16 02:47:20 +02:00

sdk/log: Refine BenchmarkProcessor (#5607)

Add a benchmark that shows that a processor that adds an attribute may
not introduce a heap allocation (as long as the log record still has <=
5 attributes).
This commit is contained in:
Robert Pająk 2024-07-11 19:51:25 +02:00 committed by GitHub
parent 55f9b5c274
commit d6aa213a7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,27 +31,39 @@ func BenchmarkProcessor(b *testing.B) {
},
},
{
name: "ModifyTimestampSimple",
name: "SetTimestampSimple",
f: func() Processor {
return timestampDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "ModifyTimestampBatch",
name: "SetTimestampBatch",
f: func() Processor {
return timestampDecorator{NewBatchProcessor(noopExporter{})}
},
},
{
name: "ModifyAttributesSimple",
name: "AddAttributesSimple",
f: func() Processor {
return attrDecorator{NewSimpleProcessor(noopExporter{})}
return attrAddDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "ModifyAttributesBatch",
name: "AddAttributesBatch",
f: func() Processor {
return attrDecorator{NewBatchProcessor(noopExporter{})}
return attrAddDecorator{NewBatchProcessor(noopExporter{})}
},
},
{
name: "SetAttributesSimple",
f: func() Processor {
return attrSetDecorator{NewSimpleProcessor(noopExporter{})}
},
},
{
name: "SetAttributesBatch",
f: func() Processor {
return attrSetDecorator{NewBatchProcessor(noopExporter{})}
},
},
} {
@ -89,11 +101,21 @@ func (e timestampDecorator) OnEmit(ctx context.Context, r Record) error {
return e.Processor.OnEmit(ctx, r)
}
type attrDecorator struct {
type attrAddDecorator struct {
Processor
}
func (e attrDecorator) OnEmit(ctx context.Context, r Record) error {
func (e attrAddDecorator) OnEmit(ctx context.Context, r Record) error {
r = r.Clone()
r.AddAttributes(log.String("add", "me"))
return e.Processor.OnEmit(ctx, r)
}
type attrSetDecorator struct {
Processor
}
func (e attrSetDecorator) OnEmit(ctx context.Context, r Record) error {
r = r.Clone()
r.SetAttributes(log.String("replace", "me"))
return e.Processor.OnEmit(ctx, r)