Skip to content

Commit 2df5ba3

Browse files
authored
Merge pull request #510 from prometheus/beorn7/timer
Return observed duration from Timer.ObserveDuration
2 parents 32b1bb4 + 48d3ae7 commit 2df5ba3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

prometheus/timer.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer {
3939

4040
// ObserveDuration records the duration passed since the Timer was created with
4141
// NewTimer. It calls the Observe method of the Observer provided during
42-
// construction with the duration in seconds as an argument. ObserveDuration is
43-
// usually called with a defer statement.
42+
// construction with the duration in seconds as an argument. The observed
43+
// duration is also returned. ObserveDuration is usually called with a defer
44+
// statement.
4445
//
4546
// Note that this method is only guaranteed to never observe negative durations
4647
// if used with Go1.9+.
47-
func (t *Timer) ObserveDuration() {
48+
func (t *Timer) ObserveDuration() time.Duration {
49+
d := time.Since(t.begin)
4850
if t.observer != nil {
49-
t.observer.Observe(time.Since(t.begin).Seconds())
51+
t.observer.Observe(d.Seconds())
5052
}
53+
return d
5154
}

0 commit comments

Comments
 (0)