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 exception.event event attribute. #747

Conversation

Oberon00
Copy link
Member

@Oberon00 Oberon00 commented Jul 28, 2020

Exceptions themselves are objects, not events, but several events related to them can happen. This PR adds a required semantic convention attribute to describe which one it was.

Be sure to read the discussion at #697 (comment).

@Oberon00 Oberon00 added area:error-reporting Related to error reporting area:semantic-conventions Related to semantic conventions area:api Cross language API specification issue spec:trace Related to the specification/trace directory labels Jul 28, 2020
@iNikem
Copy link
Contributor

iNikem commented Jul 28, 2020

Can you provide a use-case or some example when and how this new field could be used?

@Oberon00
Copy link
Member Author

A handled exception is something entirely different from a thrown exception, I think we need a way to distinguish this. So the use case would be to display this information in the backend and use it in error analysis.

I will add some examples. 👍

@Oberon00
Copy link
Member Author

Oberon00 commented Jul 28, 2020

@iNikem Since you are familiar with the original exception attributes, what kinds of exception events do you expect to be recorded?


static void someMethodThatMayThrow() {
someMethodWithCleanup();
} // Instrumentation may record a *rethrown* exception here
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we should have a special escaped event for this special case where an exception was detected to leave a function by an instrumentation, even though there is no catch block in it (the instrumentation may have added one).

@iNikem
Copy link
Contributor

iNikem commented Jul 28, 2020

My biggest concern about this PR is that I cannot imagine how auto-instrumentations will provide this information. E.g. I detect that exception was thrown, I record that on the current span right away. Next that exception was actually handled, but I cannot change that attribute any more, event is already recorded. And that exception handling can occur in totally different class/method, although still during the same span.

Do you propose to call recordException several times with the same exception but different events?

@Oberon00
Copy link
Member Author

Oberon00 commented Jul 28, 2020

No, actually I recommend to only record thrown and maybe rethrown (please read the diff). I also expect that the other enum values will not see much use (EDIT: Except for manual instrumentation). Part of the reason for them to exist to make clear what does not count as (re)thrown.

@Oberon00
Copy link
Member Author

Oberon00 commented Jul 28, 2020

Next that exception was actually handled, but I cannot change that attribute any more

If you want to record both events, you should create two events for the same exception object. If not, this PR recommends to record only thrown.

EDIT:

Quoting the PR:

Note that instrumentations are not expected to record all exception events.
Typically, thrown is the most important event.

But if you want to record both events, now you can.

Do you propose to call recordException several times with the same exception but different events?

If you want to record multiple events for the same exception object (which this PR does not recommend), then yes, that's how I imagine it. After, all as I said in the PR description

Exceptions themselves are objects, not events, but several events related to them can happen.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

I agree with @iNikem, it's not even really about auto instrumentation, but any library instrumentation will generally only be able to receive errors based on some error handler or similar callback. Without the actual library providing this information, I don't see how instrumentation could ever derive it except for very rare cases.

specification/trace/semantic_conventions/exceptions.md Outdated Show resolved Hide resolved
@Oberon00
Copy link
Member Author

Instrumentations will know if they last saw the exception in flight or being handled/swallowed (often they only can detect events of he former kind, e.g. by wrapping a fumction in a try/catch). I think my current choice of enum values may be poor, but this binary distinction is what I care about most.

@iNikem
Copy link
Contributor

iNikem commented Jul 29, 2020

Ok,you want to distinguish two classes of exceptions: handled and not handled. But even inside one span there may be significant distance between where exception is thrown and where it is caught and handled. That distance may even cross library boundaries. For auto-instrumentation (and for library authors in fact) this means a choice between two ways to handle exception. One is extremely simple: you see exception, you record it. Another is much more complicated: you see exception, wait until it gets caught/handled or thrown outside of the span boundaries, then decide which event to record.

I hope to be mistaken, but at the moment I think this proposal will significantly complicate my job as auto-instrumentation maintainer without that much of benefit for an end-user.

@iNikem
Copy link
Contributor

iNikem commented Jul 29, 2020

A handled exception is something entirely different from a thrown exception, I think we need a way to distinguish this. So the use case would be to display this information in the backend and use it in error analysis.

In my past in Plumbr we looked at how far exceptions/error statuses got propagated up from the span where they were created. This gave us almost the same information, IMHO.

@Oberon00
Copy link
Member Author

One is extremely simple: you see exception, you record it.

Why do you think this proposal changes this?

@Oberon00
Copy link
Member Author

Oberon00 commented Jul 29, 2020

A typical auto-instrumentation will wrap things in catch blocks and record throw exceptions, then rethrow. That's it. The only difference with this proposal would be that it would additionally set exception.event=thrown.

@Oberon00
Copy link
Member Author

@anuraaga

any library instrumentation will generally only be able to receive errors based on some error handler or similar callback. Without the actual library providing this information

Won't this information usually be in the documentation in the callback? Sometimes you can even do things like return a boolean whether to rethrow or swallow the exception (instrumentation would then indicate rethrow I guess and write throw on the exception)

@iNikem
Copy link
Contributor

iNikem commented Jul 29, 2020

A typical auto-instrumentation will wrap things in catch blocks and record throw exceptions, then rethrow. That's it. The only difference with this proposal would be that it would additionally set exception.event=thrown.

And then this exception will be caught by the method above and handled. If end user relies on different events "thrown/handled" to reflect what has actually happened, the above situation will be misleading.

I think my objection boils down to the following. Current recordException is very "local" action. Decision of thrown vs handled cannot be made locally. And this change "local -> non local" significantly complicates auto instrumentations. If auto instrumentation will always mark exceptions as handled, then what's the point?

@Oberon00
Copy link
Member Author

And this change "local -> non local" significantly complicates auto instrumentations.

I am not suggesting to change that.

If end user relies on different events "thrown/handled" to reflect what has actually happened

Instrumentation can only tell what happened at the point where it saw the exception. It will not be able to tell what happened later.

I think you object because you think that I want this to change, but I don't. I think you think this because the enum would be mostly useless otherwise, and I'm starting to agree.

I will probably replace this WIP PR with a new one that simply adds the requirement:

recordException MUST ONLY be called for exceptions that are not already known to be handled.

@iNikem
Copy link
Contributor

iNikem commented Jul 29, 2020

I think you think this because the enum would be mostly useless otherwise, and I'm starting to agree.

Yes, that is correct summary of my thoughts :)

recordException MUST ONLY be called for exceptions that are not already known to be handled.

Do you mean here that if auto-instrumentation does not know what will happen in the future with this exception, then it is Ok for it to record this exception? I hope so :)

Bun on the other hand, why do you want to forbid application developers to record arbitrary exceptions, even handled ones, if they wish so?

@Oberon00
Copy link
Member Author

But on the other hand, why do you want to forbid application developers to record arbitrary exceptions, even handled ones, if they wish so?

Hmm, for that case something like the enum would be useful 🤔 Or maybe a boolean handled.

@Oberon00
Copy link
Member Author

Do you mean here that if auto-instrumentation does not know what will happen in the future with this exception, then it is Ok for it to record this exception?

Yes, because I think the typical case for auto-instrumentation would be to observe an exception flying out of some function, and having no idea what happens afterwards. This case should definitely be allowed and simple.

@Oberon00
Copy link
Member Author

I will probably replace this WIP PR with a new one that simply adds the requirement:

recordException MUST ONLY be called for exceptions that are not already known to be handled.

@iNikem reminded me that we already have a PR that does this open: #521.

@Oberon00
Copy link
Member Author

Oberon00 commented Aug 7, 2020

Superseded by #761

@Oberon00 Oberon00 closed this Aug 7, 2020
@Oberon00 Oberon00 deleted the exception-event-event branch December 18, 2020 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Cross language API specification issue area:error-reporting Related to error reporting area:semantic-conventions Related to semantic conventions spec:trace Related to the specification/trace directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants