Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors to spans #1260

Merged
merged 14 commits into from
Apr 23, 2024
Merged

Add errors to spans #1260

merged 14 commits into from
Apr 23, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Apr 5, 2024

What?

Adding errors to the API spans that currently exist.

Why?

When a user views the traces for the test, it's useful to see whether an error occurred and in which API call. This will help highlight spans where errors occurred and therefore caused the test iteration to fail.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

#1249

@ankur22 ankur22 marked this pull request as draft April 5, 2024 14:23
@ankur22 ankur22 changed the base branch from main to refactor/for-span-apis April 5, 2024 14:23
@ankur22 ankur22 marked this pull request as ready for review April 8, 2024 16:01
@ankur22 ankur22 requested a review from inancgumus April 8, 2024 16:02
@andrewslotin andrewslotin self-requested a review April 11, 2024 12:04
Copy link
Contributor

@andrewslotin andrewslotin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor comments. @inancgumus, WDYT?

common/browser.go Outdated Show resolved Hide resolved
common/page.go Outdated Show resolved Hide resolved
common/page.go Outdated Show resolved Hide resolved
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the overall PR 👍

I have some wonderings:

  1. Why is SpanRecordError exported?
  2. Can we use the existing error? Is there a reason for repurposing a new error message? Should we repurpose the original error and directly use it instead?
  3. Weak suggestion: Can we register span errors in the mapping layer (instead of intermingling or handling them into the core logic)?

Base automatically changed from refactor/for-span-apis to main April 22, 2024 10:10
@ankur22
Copy link
Collaborator Author

ankur22 commented Apr 22, 2024

I'm happy with the overall PR 👍

I have some wonderings:

  1. Why is SpanRecordError exported?
  2. Can we use the existing error? Is there a reason for repurposing a new error message? Should we repurpose the original error and directly use it instead?
  3. Weak suggestion: Can we register span errors in the mapping layer (instead of intermingling or handling them into the core logic)?
  1. Good spot, i copied the format from the other APIs in the file. Fixed in c0c2a6e
  2. I'm not sure what you mean here, Could you give an example?
  3. This is something I was thinking about too. I think it's worth experimenting but in another PR. It would involve changing the method signature to always expect a context.Context, which is generally good, but also confusing in our case since the context would only carry the trace information and not be used to terminate the iteration/method 🤔

@inancgumus
Copy link
Member

inancgumus commented Apr 22, 2024

@ankur22

  1. Good spot, i copied the format from the other APIs in the file. Fixed in c0c2a6e

👍

  1. I'm not sure what you mean here, Could you give an example?

Sure. I mean this (using the existing error message):

err := errors.New("existing browser context must be closed before creating a new one")
spanRecordError(span, err)
return nil, err

Instead of:

err := errors.New("existing browser context must be closed before creating a new one")
spanRecordError(span, "browserContext already exists", err)
return nil, err

In the current version, there are two error messages:

  1. "existing browser context must be closed before creating a new one"
  2. "browserContext already exists"

I thought maybe we could use a single error message. If the existing error messages are too verbose, we could repurpose them to be compatible with span error messages. Keeping the error messages consistent will prevent confusion in the future and also lead to less code.

  1. This is something I was thinking about too. I think it's worth experimenting but in another PR. It would involve changing the method signature to always expect a context.Context, which is generally good, but also confusing in our case since the context would only carry the trace information and not be used to terminate the iteration/method 🤔

Context is also used to carry information. So, it's fine to experiment with it.

@ankur22
Copy link
Collaborator Author

ankur22 commented Apr 23, 2024

  1. I'm not sure what you mean here, Could you give an example?

Sure. I mean this (using the existing error message):

err := errors.New("existing browser context must be closed before creating a new one")
spanRecordError(span, err)
return nil, err

Instead of:

err := errors.New("existing browser context must be closed before creating a new one")
spanRecordError(span, "browserContext already exists", err)
return nil, err

In the current version, there are two error messages:

  1. "existing browser context must be closed before creating a new one"
  2. "browserContext already exists"

I thought maybe we could use a single error message. If the existing error messages are too verbose, we could repurpose them to be compatible with span error messages. Keeping the error messages consistent will prevent confusion in the future and also lead to less code.

I see now. Adding a description of the error seems to be a requirement when recording the error in the span:

func spanRecordError(span trace.Span, description string, err error) {
	span.SetStatus(codes.Error, description)
	span.RecordError(err)
}

Any other options?

@inancgumus
Copy link
Member

@ankur22

I see now. Adding a description of the error seems to be a requirement when recording the error in the span.

Yes, but the description doesn't have to be a different error. For example.

It seems that the description of the error is mostly just the error
itself according to other services we've looked at.
@ankur22
Copy link
Collaborator Author

ankur22 commented Apr 23, 2024

Yes, but the description doesn't have to be a different error. For example.

Nice find, if that's what they're doing then I will do the same 👍 Changed in 2207e4b

@ankur22 ankur22 merged commit f6e6fc4 into main Apr 23, 2024
17 checks passed
@ankur22 ankur22 deleted the feat/add-errors-on-span branch April 23, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants