From b9752eb5dc193354a5b19453a6dea3e149a3c056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 9 Apr 2024 10:22:50 +0200 Subject: [PATCH] sdk/log: Exporter has to be concurrent-safe (#5181) --- sdk/log/exporter.go | 4 ++++ sdk/log/simple.go | 10 +--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sdk/log/exporter.go b/sdk/log/exporter.go index e3c2cd914..6ebf061db 100644 --- a/sdk/log/exporter.go +++ b/sdk/log/exporter.go @@ -15,6 +15,10 @@ import ( ) // Exporter handles the delivery of log records to external receivers. +// +// Any of the Exporter's methods may be called concurrently with itself +// or with other methods. It is the responsibility of the Exporter to manage +// this concurrency. type Exporter interface { // Export transmits log records to a receiver. // diff --git a/sdk/log/simple.go b/sdk/log/simple.go index 819501ad7..dc06f7abd 100644 --- a/sdk/log/simple.go +++ b/sdk/log/simple.go @@ -5,7 +5,6 @@ package log // import "go.opentelemetry.io/otel/sdk/log" import ( "context" - "sync" ) // Compile-time check SimpleProcessor implements Processor. @@ -13,8 +12,7 @@ var _ Processor = (*SimpleProcessor)(nil) // SimpleProcessor is an processor that synchronously exports log records. type SimpleProcessor struct { - exporterMu sync.Mutex - exporter Exporter + exporter Exporter } // NewSimpleProcessor is a simple Processor adapter. @@ -34,8 +32,6 @@ func NewSimpleProcessor(exporter Exporter) *SimpleProcessor { // OnEmit batches provided log record. func (s *SimpleProcessor) OnEmit(ctx context.Context, r Record) error { - s.exporterMu.Lock() - defer s.exporterMu.Unlock() return s.exporter.Export(ctx, []Record{r}) } @@ -46,14 +42,10 @@ func (s *SimpleProcessor) Enabled(context.Context, Record) bool { // Shutdown shuts down the expoter. func (s *SimpleProcessor) Shutdown(ctx context.Context) error { - s.exporterMu.Lock() - defer s.exporterMu.Unlock() return s.exporter.Shutdown(ctx) } // ForceFlush flushes the exporter. func (s *SimpleProcessor) ForceFlush(ctx context.Context) error { - s.exporterMu.Lock() - defer s.exporterMu.Unlock() return s.exporter.ForceFlush(ctx) }