-
Notifications
You must be signed in to change notification settings - Fork 86
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 support for instrumented functions which return Result #28
Conversation
37ec0bc
to
9e15628
Compare
hm, little unfortunate to have a third error handling config (on top of the Looks like the error macro does at least currently result in the span state being set to error, is this change then mostly renaming the recorded otel event name from Maybe we could add that option to the exception field config to include that? |
Yeah, currently the span is set to error but the Additionally, as it also fits the exception convention, it is duplicated into an exception field. Note that you can configure both things independently. The current We could use the same config option struct, but I would rename the fields to better reflect the outcome. If you are okay with this breaking change. I would propose: struct Config {
/// If a function is instrumented and returns a `Result`, should the error
/// value be propagated to the span status.
///
/// Without this enabled, the span status will be "Error" with an empty description
/// when at least one error event is recorded in the span.
error_events_to_status: bool,
/// If an event with an empty name and a field named `error` is recorded,
/// should the event be rewritten to have the name `exception` and the field `exception.message`
///
/// Follows the semantic conventions for exceptions.
error_events_to_exceptions: bool,
/// If an error value is recorded on an event, should the otel fields be
/// added to the corresponding span.
///
/// Note that this uses tracings `record_error` which is only implemented for `(dyn Error + 'static)`.
error_records_to_exceptions: bool,
/// If an error value is recorded on an event/span, should the otel
/// semantic convention for execptions be added.
///
/// Note that this uses tracings `record_error` which is only implemented for `(dyn Error + 'static)`.
error_fields_to_exceptions: bool,
} |
I think the internal config struct update makes sense to consolidate and as it's not public there is no breaking change. I think the larger question is what config to expose via the Are there use cases for the full 4x4 matrix of options? or could the options be slimmed down to just 1) do error events apply semantic conventions, 2) does |
Could help reduce the conceptual overhead of using this library. Basically have semantic conventions added by default with opt-out via config, and if you want to customize specific behavior, use the |
9e15628
to
15e1507
Compare
I enabled the SemConv mappings by default now, changed the names to better reflect the purpose (with backwards depreciation warning) too. Regarding slimming it down: I think |
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.
@valkum apologies for the delay, I think this is a reasonable step forward. I think we can merge this once rebased
Renames the config struct in preparation of adding more config fields.
b57678a
to
e6330d6
Compare
Sorry, missed the example check error. |
Currently, the instrumentation macro emits a single event after the function call, but in the current span, with just a field named error set. This commit adds support to use this event to fill the span status error description with the content of the error field of this event. The mapping is optional and can be configured using the ErrorFieldConfig.
e6330d6
to
d5bc52c
Compare
Looks great thanks @valkum |
Motivation
Currently, the tracing instrumentation macro emits a single event after the function call, but in the current span, with just a field named error set.
For example:
gets roughly expanded to
In the error case of the result, the macro will emit an error level event with just an
error
field set to the display (or debug) value of the returned error.While there exists support for the Error primitive in tracing, the primitive only supports 'static Errors. See tokio-rs/tracing#1308
Solution
This PR adds support to use this event to fill the span status error description with the content of the error field of this event. Additionally, this ass support to emit these events (or manually created ones that follow the same format) as OTel events following the exception convention.
The operation is optional and can be configured using the
ErrorFieldConfig
.This seems like another hack similar to
otel.*
fields, but should reduce some boilerplate in existing codebases.I propose to keep this until
tracing
improves support for Error fields.