feat: create Exception from tracing event#359
Conversation
flub
left a comment
There was a problem hiding this comment.
I like the general approach to this, thanks for starting to work on it. Some high level questions I have though:
- I would kind of expect to be able to pass an
std::error::Errortype in theerrorfield of an trancing span/event and for the sentry integration to extract the type and value and backtrace just like it would do for directly capturing such error types. Can this be done? - I think the crate's doc comment should clearly document that the integration treats those tracing fields specially and how to use them to create sentry errors.
- I'm not entirely sure if I'm reading this code correctly, but does this try to create an exception for any tracing event? Should it only do this for error-level events maybe?
| let culprit = match (event.metadata().file(), event.metadata().line()) { | ||
| (Some(f), Some(l)) => Some(format!("{}L{}", f, l)), | ||
| _ => None, | ||
| }; |
There was a problem hiding this comment.
I've been trying to find out what this field is for and so far the SDK folks seem to be telling me that this is an internal field that's set during processing and also that it is deprecated. So we shouldn't set it here.
(see also getsentry/relay#1082)
There was a problem hiding this comment.
Removed!
I tried to shoehorn the filename and line number of the span into the exception somehow, but perhaps this information will be included elsewhere? I am unsure about this, since there's no stacktrace available.
There was a problem hiding this comment.
Yes, it would be nice to have this somewhere. But indeed without a stacktrace that seems tricky. I'm not very familiar with the event data format, https://develop.sentry.dev/sdk/event-payloads/#other-interfaces might have info on where else could be suitable.
Yes, retrieving the error from the event is possible. The However,
Agreed. My choice of field names is arbitrary, and I'd like to align with whichever fields
Perhaps I'm misunderstanding the |
18ee3ed to
fede6f2
Compare
|
So, I've re-worked the The "ty" of the exception is still not great. For an error event, the type is Also, I do not see the "extras" in the issue (i.e. the latest event) in Sentry. In my testing, when annotating a function with It seems some more debugging is needed 😅 |
flub
left a comment
There was a problem hiding this comment.
Apologies for the delay in getting back!
| let value = visitor | ||
| .json_values | ||
| .remove(DEFAULT_ERROR_VALUE_KEY) | ||
| .map(|v| v.as_str().map(|s| s.to_owned())) | ||
| .flatten() | ||
| .or_else(|| message.clone()); |
There was a problem hiding this comment.
Is this whole thing still needed now that you discovered record_error?
There was a problem hiding this comment.
I left this branch as a fallback in the case that the event does not have any exceptions. This would at least create a single exception using what data is available from either the error or message field (in that order).
There was a problem hiding this comment.
Thoughts on handling this explicitly, versus assuming that at least one exception will always be present?
There was a problem hiding this comment.
are sentry events required to always include an exception? We could document to use some_field_name=anyhow::Error::msg("oops") instead of error="oops"` if you need an exception? I fear that leaving in a special field name could be surprising at times?
Swatinem
left a comment
There was a problem hiding this comment.
lgtm, but it would be nice to have a test for this.
| sentry-core = { version = "0.23.0", path = "../sentry-core", features = ["client"] } | ||
| sentry-backtrace = { version = "0.23.0", path = "../sentry-backtrace" } |
There was a problem hiding this comment.
why was this change necessary? I don’t see these imports being used? Please revert this in that case.
There was a problem hiding this comment.
Sorry for the delay. This dependency is used in a particular scenario where the event visitor parsed no events from an event handled as an exception: source.
There was a problem hiding this comment.
What are your thoughts on handling this scenario where the event visitor parsed no events for an exception? It seems like a particularly unlikely scenario, and handling it in the current way requiring pulling in these two extra crates.
Which parts did you have in mind, @Swatinem? I suppose it makes sense to test the |
|
Rebased again and force-pushed the changes. |
|
I think a simple test where you supply some kind of |
This change will build an exception differently than event. It will look for two hardcoded keys in the "extras" of an event: 1. "error_kind" - this is optional and defaults to "Unknown" 2. "error" - this is optional and defaults to the event's message Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
refactor: reduce public api surface refactor: rename visitor type refactor: re-use parent context/transaction handling chore: reorder trait impl to match trait Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
Signed-off-by: Sean Pianka <pianka@eml.cc>
|
@seanpianka 👋🏻 what is still needed to push this over the finish line? I might be a bit tempted to just merge this as is, as we are currently adding manual performance monitoring support and will then probably overhaul the tracing integration completely. |
|
I went ahead and merged the code with the latest upstream changes in #412 |
This PR relates to my message in #180
This change will build an exception differently than event. It will look
for two hardcoded keys in the "extras" of an event:
I am open to ideas for improving this! This PR simply gets exception
handling off the ground, but makes arbitrary assumptions about how the
tracing event will communicate the error information.