Skip to content

Commit

Permalink
Add reload errors to span
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Apr 22, 2024
1 parent c050aa5 commit 344f2f2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,9 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl
p.timeoutSettings.navigationTimeout(),
)
if err := parsedOpts.Parse(p.ctx, opts); err != nil {
return nil, fmt.Errorf("parsing reload options: %w", err)
err = fmt.Errorf("parsing reload options: %w", err)
SpanRecordError(span, "reload option parsing failed", err)
return nil, err
}

timeoutCtx, timeoutCancelFn := context.WithTimeout(p.ctx, parsedOpts.Timeout)
Expand All @@ -1080,7 +1082,9 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl

action := cdppage.Reload()
if err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {
return nil, fmt.Errorf("reloading page: %w", err)
err = fmt.Errorf("reloading page: %w", err)
SpanRecordError(span, "reload failed", err)
return nil, err
}

wrapTimeoutError := func(err error) error {
Expand All @@ -1100,7 +1104,9 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl
select {
case <-p.ctx.Done():
case <-timeoutCtx.Done():
return nil, wrapTimeoutError(timeoutCtx.Err())
err := wrapTimeoutError(timeoutCtx.Err())
SpanRecordError(span, "reload navigation timed out", err)
return nil, err
case data := <-ch:
event = data.(*NavigationEvent)
}
Expand All @@ -1116,7 +1122,9 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl
select {
case <-lifecycleEvtCh:
case <-timeoutCtx.Done():
return nil, wrapTimeoutError(timeoutCtx.Err())
err := wrapTimeoutError(timeoutCtx.Err())
SpanRecordError(span, "reload lifecycle timed out", err)
return nil, err
}

applySlowMo(p.ctx)
Expand Down

0 comments on commit 344f2f2

Please sign in to comment.