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

apm.Error implements error interface #391

Closed
psrebniak opened this issue Dec 13, 2018 · 5 comments
Closed

apm.Error implements error interface #391

psrebniak opened this issue Dec 13, 2018 · 5 comments

Comments

@psrebniak
Copy link
Contributor

Is your feature request related to a problem? Please describe.
At the moment there is no possibility to pass Error as error interface.
We have to redeclare type as type ApmError apm.Error and define methods there.

Describe the solution you'd like
func (e *Error) Error() string should be implemented

Is there any reason, why Error does not implement error interface?
I can prepare pull request for that feature if you're interested in.

@axw
Copy link
Member

axw commented Dec 14, 2018

@psrebniak apm.Error wasn't designed to be passed around as an error, but I'm interested to know why you would want to do that. It's only meant for capturing an error to be sent to Elastic APM.

@psrebniak
Copy link
Contributor Author

Ok, so let's define two usecases:

  1. http -> mux.Router -> someGetMethod -> Service (here we got error) -> [call to external api]
  2. worker -> Service (here we got error) -> [call to external api]

In first case, all errors should be handled
In second case, some errors should be ommited but returned, and we should have a possibility to raport other errors (so we cannot just disabled all raporting).

If we could pass apm.Error as error, we could return that from service, and outer function should decide what to do with this.

We use own package to check type of error, if it is ApmError - send it, otherwise - wrap as ApmError and Submit

We define errors inside Service to set apm.Span on that apm.Error.

@axw
Copy link
Member

axw commented Dec 17, 2018

OK, so in summary you would like to be able to defer the decision to call (*apm.Error).Send to your business logic layer (worker) while retaining the connection between the reported error and the inner span (e.g. for Service).

To answer your question "Is there any reason, why Error does not implement error interface?", only that I had not yet considered this scenario. Your suggestion seems reasonable to me.

I can prepare pull request for that feature if you're interested in.

That would be great, I'd be happy to review your pull request.

One request I have is that the *apm.Error should also implement the following interface, to support github.com/pkg/errors.Cause:

type causer interface {
    Cause() error
}

This would enable the handling code to inspect the underlying error. At the moment, neither Tracer.NewError nor Tracer.NewErrorLog record the original error value; they will need to be changed.

@psrebniak
Copy link
Contributor Author

psrebniak commented Dec 19, 2018

Ok, should I keep original error in Error or ErrorData?
I'm not sure because ErrorData is purged after Error.Send() and I think original error should not be removed after sending error.
I would prefer to keep it directly in Error but wanted to ask beforehand.

@axw
Copy link
Member

axw commented Dec 19, 2018

I agree, putting it directly in Error seems best.

psrebniak pushed a commit to psrebniak/apm-agent-go that referenced this issue Dec 19, 2018
psrebniak added a commit to psrebniak/apm-agent-go that referenced this issue Dec 24, 2018
psrebniak added a commit to psrebniak/apm-agent-go that referenced this issue Jan 14, 2019
@axw axw closed this as completed in #399 Jan 16, 2019
axw added a commit that referenced this issue Jan 16, 2019
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

No branches or pull requests

3 participants