Skip to content

Commit

Permalink
Add error handling on page.on(metric) handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ankur22 committed Oct 18, 2024
1 parent aefd742 commit f0e7319
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f0e7319

Please sign in to comment.