From 70000a0caacbc3c34b1bd9e82c510142c6830f56 Mon Sep 17 00:00:00 2001 From: RedAFD Date: Wed, 16 Dec 2020 13:32:53 +0800 Subject: [PATCH] use spanStoreInterface instead of *Span in active set of spanStore.(census-instrumentation/opencensus-go#1245) --- trace/spanstore.go | 10 +++++----- trace/trace.go | 8 ++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/trace/spanstore.go b/trace/spanstore.go index bdcc8db41..e601f76f2 100644 --- a/trace/spanstore.go +++ b/trace/spanstore.go @@ -49,7 +49,7 @@ func (i internalOnly) ReportActiveSpans(name string) []*SpanData { s.mu.Lock() defer s.mu.Unlock() for activeSpan := range s.active { - if s, ok := activeSpan.internal.(*span); ok { + if s, ok := activeSpan.(*span); ok { out = append(out, s.makeSpanData()) } } @@ -187,7 +187,7 @@ func (i internalOnly) ReportSpansByLatency(name string, minLatency, maxLatency t // bucketed by latency. type spanStore struct { mu sync.Mutex // protects everything below. - active map[*Span]struct{} + active map[SpanInterface]struct{} errors map[int32]*bucket latency []bucket maxSpansPerErrorBucket int @@ -196,7 +196,7 @@ type spanStore struct { // newSpanStore creates a span store. func newSpanStore(name string, latencyBucketSize int, errorBucketSize int) *spanStore { s := &spanStore{ - active: make(map[*Span]struct{}), + active: make(map[SpanInterface]struct{}), latency: make([]bucket, len(defaultLatencies)+1), maxSpansPerErrorBucket: errorBucketSize, } @@ -273,7 +273,7 @@ func (s *spanStore) resize(latencyBucketSize int, errorBucketSize int) { } // add adds a span to the active bucket of the spanStore. -func (s *spanStore) add(span *Span) { +func (s *spanStore) add(span SpanInterface) { s.mu.Lock() s.active[span] = struct{}{} s.mu.Unlock() @@ -281,7 +281,7 @@ func (s *spanStore) add(span *Span) { // finished removes a span from the active set, and adds a corresponding // SpanData to a latency or error bucket. -func (s *spanStore) finished(span *Span, sd *SpanData) { +func (s *spanStore) finished(span SpanInterface, sd *SpanData) { latency := sd.EndTime.Sub(sd.StartTime) if latency < 0 { latency = 0 diff --git a/trace/trace.go b/trace/trace.go index 0a4feeceb..861df9d39 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -65,8 +65,6 @@ type span struct { endOnce sync.Once executionTracerTaskEnd func() // ends the execution tracer span - - activeExporter *Span // corresponding exporter in the active set of spanStore } // IsRecordingEvents returns true if events are being recorded for this span. @@ -268,9 +266,7 @@ func startSpanInternal(name string, hasParent bool, parent SpanContext, remotePa ss = spanStoreForNameCreateIfNew(name) if ss != nil { s.spanStore = ss - ns := NewSpan(s) - s.activeExporter = ns - ss.add(ns) + ss.add(s) } } @@ -295,7 +291,7 @@ func (s *span) End() { sd := s.makeSpanData() sd.EndTime = internal.MonotonicEndTime(sd.StartTime) if s.spanStore != nil { - s.spanStore.finished(s.activeExporter, sd) + s.spanStore.finished(s, sd) } if mustExport { for e := range exp {