Skip to content

Commit

Permalink
avoid locking twice if there are no onending span processors
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Oct 3, 2024
1 parent 43e3438 commit f4ae0f4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,31 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) {
s.executionTracerTaskEnd()
}

sps := s.tracer.provider.getSpanProcessors()
var oesps []x.OnEndingSpanProcessor
for _, sp := range sps {
if oesp, ok := sp.sp.(x.OnEndingSpanProcessor); ok {
oesps = append(oesps, oesp)
}
}

s.mu.Lock()
if config.Timestamp().IsZero() {
s.endTime = et
} else {
s.endTime = config.Timestamp()
}
s.hasEnded = len(oesps) == 0
s.mu.Unlock()

sps := s.tracer.provider.getSpanProcessors()
for _, sp := range sps {
if oesp, ok := sp.sp.(x.OnEndingSpanProcessor); ok {
oesp.OnEnding(s)
if len(oesps) > 0 {
for _, sp := range oesps {
sp.OnEnding(s)
}
s.mu.Lock()
s.hasEnded = true
s.mu.Unlock()
}
s.mu.Lock()
s.hasEnded = true
s.mu.Unlock()

if len(sps) == 0 {
return
Expand Down

0 comments on commit f4ae0f4

Please sign in to comment.