diff --git a/common/browser.go b/common/browser.go index ac39d622c..c5cf68543 100644 --- a/common/browser.go +++ b/common/browser.go @@ -551,7 +551,7 @@ func (b *Browser) NewContext(opts goja.Value) (*BrowserContext, error) { if b.context != nil { err := errors.New("existing browser context must be closed before creating a new one") - SpanRecordError(span, "browserContext already exists", err) + spanRecordError(span, "browserContext already exists", err) return nil, err } @@ -560,21 +560,21 @@ func (b *Browser) NewContext(opts goja.Value) (*BrowserContext, error) { b.logger.Debugf("Browser:NewContext", "bctxid:%v", browserContextID) if err != nil { err := fmt.Errorf("creating browser context ID %s: %w", browserContextID, err) - SpanRecordError(span, "browserContext creation in Chrome failed", err) + spanRecordError(span, "browserContext creation in Chrome failed", err) return nil, err } browserCtxOpts := NewBrowserContextOptions() if err := browserCtxOpts.Parse(b.ctx, opts); err != nil { err := fmt.Errorf("parsing newContext options: %w", err) - SpanRecordError(span, "new browserContext options parsing failed", err) + spanRecordError(span, "new browserContext options parsing failed", err) return nil, err } browserCtx, err := NewBrowserContext(b.ctx, b, browserContextID, browserCtxOpts, b.logger) if err != nil { err := fmt.Errorf("new context: %w", err) - SpanRecordError(span, "new browserContext creation failed", err) + spanRecordError(span, "new browserContext creation failed", err) return nil, err } @@ -593,13 +593,13 @@ func (b *Browser) NewPage(opts goja.Value) (*Page, error) { browserCtx, err := b.NewContext(opts) if err != nil { err := fmt.Errorf("new page: %w", err) - SpanRecordError(span, "new browserContext creation failed", err) + spanRecordError(span, "new browserContext creation failed", err) return nil, err } page, err := browserCtx.NewPage() if err != nil { - SpanRecordError(span, "new page creation failed", err) + spanRecordError(span, "new page creation failed", err) return nil, err } diff --git a/common/browser_context.go b/common/browser_context.go index 86a968b48..046d1b108 100644 --- a/common/browser_context.go +++ b/common/browser_context.go @@ -220,7 +220,7 @@ func (b *BrowserContext) NewPage() (*Page, error) { p, err := b.browser.newPageInContext(b.id) if err != nil { err := fmt.Errorf("creating new page in browser context: %w", err) - SpanRecordError(span, "failed to create a new page", err) + spanRecordError(span, "failed to create a new page", err) return nil, err } diff --git a/common/element_handle.go b/common/element_handle.go index be7669ed8..165e341e8 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -1184,7 +1184,7 @@ func (h *ElementHandle) Screenshot( buf, err := s.screenshotElement(h, opts) if err != nil { err := fmt.Errorf("taking screenshot of elementHandle: %w", err) - SpanRecordError(span, "failed to take screenshot", err) + spanRecordError(span, "failed to take screenshot", err) return nil, err } diff --git a/common/locator.go b/common/locator.go index 383d10673..441e430a3 100644 --- a/common/locator.go +++ b/common/locator.go @@ -65,7 +65,7 @@ func (l *Locator) Click(opts *FrameClickOptions) error { if err := l.click(opts); err != nil { err := fmt.Errorf("clicking on %q: %w", l.selector, err) - SpanRecordError(span, "click failed", err) + spanRecordError(span, "click failed", err) return err } @@ -522,12 +522,12 @@ func (l *Locator) Type(text string, opts goja.Value) error { copts := NewFrameTypeOptions(l.frame.defaultTimeout()) if err := copts.Parse(l.ctx, opts); err != nil { err := fmt.Errorf("parsing type options: %w", err) - SpanRecordError(span, "type option parsing failed", err) + spanRecordError(span, "type option parsing failed", err) return err } if err := l.typ(text, copts); err != nil { err := fmt.Errorf("typing %q in %q: %w", text, l.selector, err) - SpanRecordError(span, "type failed", err) + spanRecordError(span, "type failed", err) return err } diff --git a/common/page.go b/common/page.go index b4f2e47e7..987833571 100644 --- a/common/page.go +++ b/common/page.go @@ -658,7 +658,7 @@ func (p *Page) Close(_ goja.Value) error { add := runtime.RemoveBinding(webVitalBinding) if err := add.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil { err := fmt.Errorf("internal error while removing binding from page: %w", err) - SpanRecordError(span, "close failed due to internal error", err) + spanRecordError(span, "close failed due to internal error", err) return err } @@ -679,7 +679,7 @@ func (p *Page) Close(_ goja.Value) error { } err := fmt.Errorf("closing a page: %w", err) - SpanRecordError(span, "close failed", err) + spanRecordError(span, "close failed", err) return err } @@ -832,7 +832,7 @@ func (p *Page) Goto(url string, opts *FrameGotoOptions) (*Response, error) { resp, err := p.MainFrame().Goto(url, opts) if err != nil { - SpanRecordError(span, "goto failed", err) + spanRecordError(span, "goto failed", err) return nil, err } @@ -996,7 +996,7 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl ) if err := parsedOpts.Parse(p.ctx, opts); err != nil { err := fmt.Errorf("parsing reload options: %w", err) - SpanRecordError(span, "reload option parsing failed", err) + spanRecordError(span, "reload option parsing failed", err) return nil, err } @@ -1024,7 +1024,7 @@ 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 { err := fmt.Errorf("reloading page: %w", err) - SpanRecordError(span, "reload failed", err) + spanRecordError(span, "reload failed", err) return nil, err } @@ -1046,7 +1046,7 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl case <-p.ctx.Done(): case <-timeoutCtx.Done(): err := wrapTimeoutError(timeoutCtx.Err()) - SpanRecordError(span, "reload navigation timed out", err) + spanRecordError(span, "reload navigation timed out", err) return nil, err case data := <-ch: event = data.(*NavigationEvent) @@ -1064,7 +1064,7 @@ func (p *Page) Reload(opts goja.Value) (*Response, error) { //nolint:funlen,cycl case <-lifecycleEvtCh: case <-timeoutCtx.Done(): err := wrapTimeoutError(timeoutCtx.Err()) - SpanRecordError(span, "reload lifecycle timed out", err) + spanRecordError(span, "reload lifecycle timed out", err) return nil, err } @@ -1084,7 +1084,7 @@ func (p *Page) Screenshot(opts *PageScreenshotOptions, sp ScreenshotPersister) ( buf, err := s.screenshotPage(p, opts) if err != nil { err := fmt.Errorf("taking screenshot of page: %w", err) - SpanRecordError(span, "screenshot failed", err) + spanRecordError(span, "screenshot failed", err) return nil, err } @@ -1256,7 +1256,7 @@ func (p *Page) WaitForNavigation(opts *FrameWaitForNavigationOptions) (*Response resp, err := p.frameManager.MainFrame().WaitForNavigation(opts) if err != nil { - SpanRecordError(span, "waiting for navigation failed", err) + spanRecordError(span, "waiting for navigation failed", err) return nil, err } diff --git a/common/trace.go b/common/trace.go index a0bdbcdc8..d408db505 100644 --- a/common/trace.go +++ b/common/trace.go @@ -58,10 +58,10 @@ func TraceEvent( return ctx, browsertrace.NoopSpan{} } -// SpanRecordError will set the status of the span to error and record the +// spanRecordError will set the status of the span to error and record the // error on the span. Check the documentation for trace.SetStatus and // trace.RecordError for more details. -func SpanRecordError(span trace.Span, description string, err error) { +func spanRecordError(span trace.Span, description string, err error) { span.SetStatus(codes.Error, description) span.RecordError(err) }