Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit e736602

Browse files
authored
fix memory leak cause by the spanStore.(census-instrumentation/opence… (#1246)
* fix memory leak in the spanStore
1 parent 61c7a2b commit e736602

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

trace/spanstore.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (i internalOnly) ReportActiveSpans(name string) []*SpanData {
4949
s.mu.Lock()
5050
defer s.mu.Unlock()
5151
for activeSpan := range s.active {
52-
if s, ok := activeSpan.internal.(*span); ok {
52+
if s, ok := activeSpan.(*span); ok {
5353
out = append(out, s.makeSpanData())
5454
}
5555
}
@@ -187,7 +187,7 @@ func (i internalOnly) ReportSpansByLatency(name string, minLatency, maxLatency t
187187
// bucketed by latency.
188188
type spanStore struct {
189189
mu sync.Mutex // protects everything below.
190-
active map[*Span]struct{}
190+
active map[SpanInterface]struct{}
191191
errors map[int32]*bucket
192192
latency []bucket
193193
maxSpansPerErrorBucket int
@@ -196,7 +196,7 @@ type spanStore struct {
196196
// newSpanStore creates a span store.
197197
func newSpanStore(name string, latencyBucketSize int, errorBucketSize int) *spanStore {
198198
s := &spanStore{
199-
active: make(map[*Span]struct{}),
199+
active: make(map[SpanInterface]struct{}),
200200
latency: make([]bucket, len(defaultLatencies)+1),
201201
maxSpansPerErrorBucket: errorBucketSize,
202202
}
@@ -273,15 +273,15 @@ func (s *spanStore) resize(latencyBucketSize int, errorBucketSize int) {
273273
}
274274

275275
// add adds a span to the active bucket of the spanStore.
276-
func (s *spanStore) add(span *Span) {
276+
func (s *spanStore) add(span SpanInterface) {
277277
s.mu.Lock()
278278
s.active[span] = struct{}{}
279279
s.mu.Unlock()
280280
}
281281

282282
// finished removes a span from the active set, and adds a corresponding
283283
// SpanData to a latency or error bucket.
284-
func (s *spanStore) finished(span *Span, sd *SpanData) {
284+
func (s *spanStore) finished(span SpanInterface, sd *SpanData) {
285285
latency := sd.EndTime.Sub(sd.StartTime)
286286
if latency < 0 {
287287
latency = 0

trace/trace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func startSpanInternal(name string, hasParent bool, parent SpanContext, remotePa
266266
ss = spanStoreForNameCreateIfNew(name)
267267
if ss != nil {
268268
s.spanStore = ss
269-
ss.add(NewSpan(s))
269+
ss.add(s)
270270
}
271271
}
272272

@@ -291,7 +291,7 @@ func (s *span) End() {
291291
sd := s.makeSpanData()
292292
sd.EndTime = internal.MonotonicEndTime(sd.StartTime)
293293
if s.spanStore != nil {
294-
s.spanStore.finished(NewSpan(s), sd)
294+
s.spanStore.finished(s, sd)
295295
}
296296
if mustExport {
297297
for e := range exp {

0 commit comments

Comments
 (0)