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

sdk/log: Exporter has to be concurrent-safe (#5181)

This commit is contained in:
Robert Pająk 2024-04-09 10:22:50 +02:00 committed by GitHub
parent a4a9e24d8c
commit b9752eb5dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 9 deletions

View File

@ -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.
//

View File

@ -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)
}