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

Proposal for a Span#Error #248

Closed
jpkrohling opened this issue Oct 29, 2019 · 9 comments · Fixed by #473
Closed

Proposal for a Span#Error #248

jpkrohling opened this issue Oct 29, 2019 · 9 comments · Fixed by #473
Labels
area:trace Part of OpenTelemetry tracing pkg:API Related to an API package

Comments

@jpkrohling
Copy link
Member

When instrumenting the Jaeger Operator, I find myself repeating calls like this:

	if err != nil {
		span.SetStatus(codes.Internal)
		span.SetAttribute(key.String("error", err.Error()))
		return err
	}

Perhaps it's a sign that the API could have a span.Error() function, so that it can be called as follows:

	if err != nil {
		return span.Error(err)
	}

This new function could accept an array of ErrorOptions, allowing callers to override the error code and possibly the attribute name.

@dmathieu
Copy link
Member

How about an internal handleError method in your operator:

func handleError(span trace.Span, err error) error {
  span.SetStatus(codes.Internal)
  span.SetAttribute(key.String("error", err.Error()))
  return err
}

Then, we're not setting up a new public method for error handling, and you can still reduce code repetition.

@jpkrohling
Copy link
Member Author

That is certainly a solution, but perhaps this is a pattern that will repeat for pretty much all other Go projects ?

@dmathieu
Copy link
Member

Another solution is the discussion in #174.

@jpkrohling
Copy link
Member Author

I understand #174 to be a way for my application to be called back when there's an error in an internal OpenTelemetry component. This issue here is about adding "error" attributes to an active span.

@jmacd
Copy link
Contributor

jmacd commented Oct 30, 2019

(Yes, #174 is unrelated.)

This issue points out a flaw in the current implementation of SetStatus(), which takes a code but not a message string. The specification says a status is a pair of a code and a string--you shouldn't have to set the message as a separate span attribute. (See https://github.com/open-telemetry/opentelemetry-proto/blob/7b88843aed39bc270ffa991dabe2d18f7b717c0a/opentelemetry/proto/trace/v1/trace.proto#L252)

Go 1.13 has some new error handling support, see https://blog.golang.org/go1.13-errors

I would consider a proposal that simplified your code to:

if err != nil {
	span.SetStatus(err)
	return err
}

What I'd really prefer is:

func F() (err error) {
   // ... start a span
   defer span.SetStatus(err)
   // ... do things
   if err != nil {
 	return err
   }

@jpkrohling
Copy link
Member Author

If SetStatus(err) would return the same err, then it would be even better to have this:

if err != nil {
	return span.SetStatus(err)
}

(the name SetStatus would be probably slightly inappropriate, though)

@rghetia rghetia added the pkg:API Related to an API package label Oct 31, 2019
@rghetia rghetia added this to the Alpha v0.3 milestone Oct 31, 2019
@rghetia rghetia added the area:trace Part of OpenTelemetry tracing label Oct 31, 2019
@jmacd
Copy link
Contributor

jmacd commented Nov 1, 2019

I could also agree that SetStatus is less appropriate because Go uses "error" extensively, that SetError is appropriate. I also suspect that having this method return the argument error will strike some as a source of cognitive overhead, which is not in the spirit of Go.

@lizthegrey
Copy link
Member

@lizthegrey
Copy link
Member

Resolved at spec meeting: we're okay to proceed for 0.3 but may need to change it for 0.4

hstan referenced this issue in hstan/opentelemetry-go Oct 15, 2020
* Bump cloud.google.com/go from 0.63.0 to 0.64.0 in /detectors/gcp

Bumps [cloud.google.com/go](https://github.com/googleapis/google-cloud-go) from 0.63.0 to 0.64.0.
- [Release notes](https://github.com/googleapis/google-cloud-go/releases)
- [Changelog](https://github.com/googleapis/google-cloud-go/blob/master/CHANGES.md)
- [Commits](googleapis/google-cloud-go@v0.63.0...v0.64.0)

Signed-off-by: dependabot[bot] <support@github.com>

* Auto-fix go.sum changes in dependent modules

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:trace Part of OpenTelemetry tracing pkg:API Related to an API package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants