-
Notifications
You must be signed in to change notification settings - Fork 896
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
Exception semantic conventions: Add example & more explanation for exception.escaped. #946
Changes from 12 commits
f8eb5e7
9d1f304
06f7c55
a47ecee
7f9ed35
370759b
d359f47
f78003e
e363eaf
d42831d
83ab7b6
b4fa424
350ff89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,24 @@ exceptions. | |
An exception SHOULD be recorded as an `Event` on the span during which it occurred. | ||
The name of the event MUST be `"exception"`. | ||
|
||
<a name="exception-end-example"></a> | ||
|
||
A typical template for an auto-instrumentation implementing this semantic convention | ||
using an [API-provided `recordException` method](../api.md#record-exception) | ||
could look like this (pseudo-Java): | ||
|
||
```java | ||
Span span = myTracer.startSpan(/*...*/); | ||
try { | ||
// Code that does the actual work which the Span represents | ||
} catch (Throwable e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering whether we should hold up adding this example till the actual API change hits OTel Java ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlosalberto OTel Java already supports this API. But the actual API has more boilerplate (I think I would have to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the example is easier to read for non-Java users without that boilerplate, but I could add it too, if you prefer. Then I can write "Java" instead of "pseudo-Java" above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be personally more comfortable with the exact code we need (i.e. through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlosalberto Now (d359f47) it's using the real OTel-Java API (at some version; seems like the Attributes are recently often changed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are trying to get the last changes through before GA, but Attributes should settle down here quite soon. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue at #946 (comment) |
||
span.recordException(e, Attributes.of("exception.escaped", true)); | ||
throw e; | ||
} finally { | ||
span.end(); | ||
} | ||
``` | ||
|
||
## Attributes | ||
|
||
The table below indicates which attributes should be added to the `Event` and | ||
|
@@ -27,9 +45,10 @@ their types. | |
| `exception.type` | string | The type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it. | `java.net.ConnectException`<br>`OSError` | See below | | ||
| `exception.message` | string | The exception message. | `Division by zero`<br>`Can't convert 'int' object to str implicitly` | See below | | ||
| `exception.stacktrace` | string | A stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG. | `Exception in thread "main" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)` | No | | ||
| `exception.escaped` | boolean | SHOULD be set to true if the exception event is recorded at a point where it is known that the exception is escaping the scope of the span (e.g. if there is an exception active just before ending the span). [1] | | No | | ||
| `exception.escaped` | boolean | SHOULD be set to true if the exception event is recorded at a point where it is known that the exception is escaping the scope of the span. [1] | | No | | ||
|
||
**[1]:** Note that an exception may still leave the scope of the span even if this was not set or set to false, if the event was recorded at an earlier time. | ||
**[1]:** An exception is considered to have escaped (or left) the scope of a span, if that span is ended while the exception is still "in flight". | ||
While it is usually not possible to determine whether some exception thrown now *will* escape the scope of a span, it is trivial to know that an exception will escape, if one checks for an active exception just before ending the span. See the [example above](#exception-end-example). It follows that an exception may still escape the scope of the span even if the `exception.escaped` attribute was not set or set to false, since that event might have been recorded at a time where it was not clear whether the exception will escape. | ||
|
||
**Additional attribute requirements:** At least one of the following sets of attributes is required: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I find this paragraph exceedingly confusing. The first sentence says "difficult to say X, but trivial to say X" (X==X). The terms "in flight" and "escape" are undefined (and not a particularly common lingo). "in flight" exception, specifically, is not observable by the code, whereas a caught exception is not "in flight".
Terms that are not ambiguous: catch exception, re-throw exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These terms are not ambiguous but also not appropriate here. If you look at the code without the auto-instrumentation in place, the exception would indeed be currently in a state where it was thrown but not yet caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurishkuro I tried to clarify in 350ff89 although I think it would also be OK to be more vague here. WDYT?