From f0e7319b383d72166c43871e7cf100cfcd65edd3 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Fri, 18 Oct 2024 20:29:44 +0100 Subject: [PATCH] Add error handling on page.on(metric) handler The most important thing to do is to handle the error and ensure that the page.on metric returns false so that the metric tag isn't update. This is being defensive, since the context has already closed and the metric emitter will not emit a metric when the context has closed. We're logging a debug log here since this information will not benefit the end user and when this error occurs they can't action on it. It could be useful for debugging though. --- common/page.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/page.go b/common/page.go index 56089b9cf..532644c4e 100644 --- a/common/page.go +++ b/common/page.go @@ -485,17 +485,21 @@ func (p *Page) urlTagName(url string, method string) (string, bool) { p.eventHandlersMu.RLock() defer p.eventHandlersMu.RUnlock() for _, h := range p.eventHandlers[EventPageMetricCalled] { - func() { + err := func() error { // Handlers can register other handlers, so we need to // unlock the mutex before calling the next handler. p.eventHandlersMu.RUnlock() defer p.eventHandlersMu.RLock() // Call and wait for the handler to complete. - h(PageOnEvent{ + return h(PageOnEvent{ Metric: em, }) }() + if err != nil { + p.logger.Debugf("urlTagName", "handler returned an error: %v", err) + return "", false + } } // If a match was found then the name field in em will have been updated.