Skip to content

Commit

Permalink
Refactor spanRecordError err as description
Browse files Browse the repository at this point in the history
It seems that the description of the error is mostly just the error
itself according to other services we've looked at.
  • Loading branch information
ankur22 committed Apr 23, 2024
1 parent d2c583d commit f6e6fc4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, err)
return nil, err
}

Expand All @@ -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, 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, 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, err)
return nil, err
}

Expand All @@ -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, err)
return nil, err
}

page, err := browserCtx.NewPage()
if err != nil {
spanRecordError(span, "new page creation failed", err)
spanRecordError(span, err)
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, err)
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, err)
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, err)
return err
}

Expand Down Expand Up @@ -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, 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, err)
return err
}

Expand Down
18 changes: 9 additions & 9 deletions common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, err)
return err
}

Expand All @@ -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, err)
return err
}

Expand Down Expand Up @@ -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, err)
return nil, err
}

Expand Down Expand Up @@ -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, err)
return nil, err
}

Expand Down Expand Up @@ -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, err)
return nil, err
}

Expand All @@ -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, err)
return nil, err
case data := <-ch:
event = data.(*NavigationEvent)
Expand All @@ -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, err)
return nil, err
}

Expand All @@ -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, err)
return nil, err
}

Expand Down Expand Up @@ -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, err)
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions common/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TraceEvent(
// 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) {
span.SetStatus(codes.Error, description)
func spanRecordError(span trace.Span, err error) {
span.SetStatus(codes.Error, err.Error())
span.RecordError(err)
}

0 comments on commit f6e6fc4

Please sign in to comment.