Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
metrics: fixes panic when using WithLabels without passing in labels …
Browse files Browse the repository at this point in the history
…through ObserveDuration
  • Loading branch information
kyleterry committed Nov 14, 2019
1 parent afda647 commit 9965640
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions instrumentation/examples/metrics_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ func main() {
mux := http.NewServeMux()
mux.Handle("/", mw.Wrap(testApp{m}))

log.Println("example server running at: http://localhost:2399/")
go http.ListenAndServe("localhost:2399", mux)

server := server.New(m, server.Options{
BindAddr: "localhost:2398",
Path: "/metrics",
BindAddr: "localhost:3050",
Path: "/",
})

log.Println("metrics server running at: http://localhost:3050/")
if err := server.Run(context.Background()); err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 3 additions & 1 deletion instrumentation/metrics/internal/prometheus/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func (t *Timer) ObserveDuration(h *collectors.TimerHandle, labels ...collectors.
t.RLock()
defer t.RUnlock()

t.labels = labels
if len(labels) > 0 {
t.labels = labels
}

if promt, ok := t.timers[h]; ok {
promt.ObserveDuration()
Expand Down

0 comments on commit 9965640

Please sign in to comment.