You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
Fixed race condition in OnEnd and added a unit test (#3951)
* Fixed race condition in OnEnd and added a test * fixed code review comments * fixed lint * Update CHANGELOG.md Co-authored-by: Robert Pająk <pellared@hotmail.com> * Update sdk/trace/simple_span_processor_test.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update sdk/trace/simple_span_processor_test.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update sdk/trace/simple_span_processor_test.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * fixed panic check --------- Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -25,7 +25,7 @@ import (
|
||||
// simpleSpanProcessor is a SpanProcessor that synchronously sends all
|
||||
// completed Spans to a trace.Exporter immediately.
|
||||
type simpleSpanProcessor struct {
|
||||
exporterMu sync.RWMutex
|
||||
exporterMu sync.Mutex
|
||||
exporter SpanExporter
|
||||
stopOnce sync.Once
|
||||
}
|
||||
@@ -54,8 +54,8 @@ func (ssp *simpleSpanProcessor) OnStart(context.Context, ReadWriteSpan) {}
|
||||
|
||||
// OnEnd immediately exports a ReadOnlySpan.
|
||||
func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
ssp.exporterMu.RLock()
|
||||
defer ssp.exporterMu.RUnlock()
|
||||
ssp.exporterMu.Lock()
|
||||
defer ssp.exporterMu.Unlock()
|
||||
|
||||
if ssp.exporter != nil && s.SpanContext().TraceFlags().IsSampled() {
|
||||
if err := ssp.exporter.ExportSpans(context.Background(), []ReadOnlySpan{s}); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user