Skip to content

Commit

Permalink
When serializing SpanModel, if there is any external modification of …
Browse files Browse the repository at this point in the history
…TAGS, it will lead to panic, add RLock before calling Send to prevent this error. (#218)

When serializing SpanModel, if there is any external modification of
TAGS, it will lead to panic, add RLock before calling Send to prevent
this error.
issues:#217

Co-authored-by: liushan <shan.liu@msn.com>
  • Loading branch information
php-lsys and shanliu committed Apr 24, 2024
1 parent de3edd7 commit 406526f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions span_implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (s *spanImpl) Finish() {
if atomic.CompareAndSwapInt32(&s.mustCollect, 1, 0) {
s.Duration = time.Since(s.Timestamp)
if s.flushOnFinish {
s.mtx.RLock()
s.tracer.reporter.Send(s.SpanModel)
s.mtx.RUnlock()
}
}
}
Expand All @@ -89,13 +91,17 @@ func (s *spanImpl) FinishedWithDuration(d time.Duration) {
if atomic.CompareAndSwapInt32(&s.mustCollect, 1, 0) {
s.Duration = d
if s.flushOnFinish {
s.mtx.RLock()
s.tracer.reporter.Send(s.SpanModel)
s.mtx.RUnlock()
}
}
}

func (s *spanImpl) Flush() {
if s.SpanModel.Debug || (s.SpanModel.Sampled != nil && *s.SpanModel.Sampled) {
s.mtx.RLock()
s.tracer.reporter.Send(s.SpanModel)
s.mtx.RUnlock()
}
}

0 comments on commit 406526f

Please sign in to comment.