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

Commit

Permalink
use spanStoreInterface instead of *Span in active set of spanStore
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoRed committed Dec 16, 2020
1 parent 464bc5f commit f61f0d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 5 additions & 5 deletions trace/spanstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
Expand Down Expand Up @@ -273,15 +273,15 @@ 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()
}

// 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
Expand Down
8 changes: 2 additions & 6 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit f61f0d5

Please sign in to comment.