Skip to content

Commit

Permalink
add trace.Span.MaxDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jslching committed Nov 8, 2023
1 parent 290c294 commit 6bcd9d2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions util/traceutil/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type ExtendedSpan interface {
// Duration returns the duration of the span.
Duration() time.Duration

// MaxDuration returns the maximum duration of the span and of all sub-spans.
MaxDuration() time.Duration

// MarshalExtended returns true if the span is set to use an extended JSON representation during marshaling.
MarshalExtended() bool

Expand Down Expand Up @@ -89,6 +92,7 @@ func (n NoopSpan) FindByName(string) Span { return
func (n NoopSpan) StartTime() utc.UTC { return utc.Zero }
func (n NoopSpan) EndTime() utc.UTC { return utc.Zero }
func (n NoopSpan) Duration() time.Duration { return 0 }
func (n NoopSpan) MaxDuration() time.Duration { return 0 }
func (n NoopSpan) MarshalExtended() bool { return false }
func (n NoopSpan) SetMarshalExtended() {}

Expand Down Expand Up @@ -235,6 +239,21 @@ func (s *RecordingSpan) Duration() time.Duration {
return s.duration
}

func (s *RecordingSpan) MaxDuration() time.Duration {
s.mutex.Lock()
defer s.mutex.Unlock()

d := s.duration
for _, ss := range s.Data.Subs {
sd := ss.MaxDuration()
if sd > d {
d = sd
}
}

return d
}

func (s *RecordingSpan) MarshalExtended() bool {
if s.extended {
return true
Expand Down

0 comments on commit 6bcd9d2

Please sign in to comment.