From 943a19c98d767040f4fe41af5aba63d23e1f41e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 6 Jun 2024 11:01:14 +0200 Subject: [PATCH 1/3] sdk/log: Remove slice allocation from SimpleProcessor.OnEmit --- sdk/log/simple.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sdk/log/simple.go b/sdk/log/simple.go index c7aa14b8706..fc5690b22d5 100644 --- a/sdk/log/simple.go +++ b/sdk/log/simple.go @@ -5,6 +5,7 @@ package log // import "go.opentelemetry.io/otel/sdk/log" import ( "context" + "sync" ) // Compile-time check SimpleProcessor implements Processor. @@ -30,9 +31,22 @@ func NewSimpleProcessor(exporter Exporter, _ ...SimpleProcessorOption) *SimplePr return &SimpleProcessor{exporter: exporter} } +var simpleProcRecordsPool = sync.Pool{ + New: func() any { + records := make([]Record, 1) + return &records + }, +} + // OnEmit batches provided log record. func (s *SimpleProcessor) OnEmit(ctx context.Context, r Record) error { - return s.exporter.Export(ctx, []Record{r}) + records := simpleProcRecordsPool.Get().(*[]Record) + (*records)[0] = r + defer func() { + simpleProcRecordsPool.Put(records) + }() + + return s.exporter.Export(ctx, *records) } // Enabled returns true. From c833de87fb65efff0292276cca75ba79d7548831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 6 Jun 2024 11:02:08 +0200 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14cd297b68f..c4813bc24d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm The package contains semantic conventions from the `v1.26.0` version of the OpenTelemetry Semantic Conventions. (#5476) - The `IsEmpty` method is added to the `Instrument` type in `go.opentelemetry.io/otel/sdk/metric`. This method is used to check if an `Instrument` instance is a zero-value. (#5431) +- `SimpleProcessor.OnEmit` in `go.opentelemetry.io/otel/trace/noop` no longer allocates a slice which makes it possible to have a zero-allocation log processing using `SimpleProcessor`. (#5493) ### Changed From ce1afb492e4e1186f08865b2293e9a734db4212a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 6 Jun 2024 15:16:13 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Tyler Yahn --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4813bc24d2..2884b4e937e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm The package contains semantic conventions from the `v1.26.0` version of the OpenTelemetry Semantic Conventions. (#5476) - The `IsEmpty` method is added to the `Instrument` type in `go.opentelemetry.io/otel/sdk/metric`. This method is used to check if an `Instrument` instance is a zero-value. (#5431) -- `SimpleProcessor.OnEmit` in `go.opentelemetry.io/otel/trace/noop` no longer allocates a slice which makes it possible to have a zero-allocation log processing using `SimpleProcessor`. (#5493) +- `SimpleProcessor.OnEmit` in `go.opentelemetry.io/otel/sdk/log` no longer allocates a slice which makes it possible to have a zero-allocation log processing using `SimpleProcessor`. (#5493) ### Changed