-
Notifications
You must be signed in to change notification settings - Fork 265
feat: add record_exception option for in_span #1911
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
base: main
Are you sure you want to change the base?
Conversation
span = nil | ||
span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind) | ||
Trace.with_span(span) { |s, c| yield s, c } | ||
rescue Exception => e # rubocop:disable Lint/RescueException | ||
span&.record_exception(e) | ||
span&.record_exception(e) if record_exception | ||
span&.status = Status.error("Unhandled exception of type: #{e.class}") |
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.
I find that Unhandled
might be misleading here. Maybe just Exception of type:
?
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.
Unhandled
was included in the message to indicate that the exception was unhandled at the time the span was finished, based on the language in the spec:
An exception SHOULD be recorded as an
Event
on the span during which it occurred if and only if it remains unhandled when the span ends and causes the span status to be set to ERROR.
It may be handled later, but it was not handled within the lifetime of the span.
The spec recommends:
When the status is set to
Error
by Instrumentation Libraries, theDescription
SHOULD be documented and predictable.
Sadly, we're violating this other recommendation, but I think changing the description would be more problematic at this point:
It's NOT RECOMMENDED to duplicate status code or
error.type
in span status description.
Non breaking change, default behaviour is preserved. Allows for the
in_span
convenience method to be configured to not capture exception events. Maintains recording of the span status as is.Related context: open-telemetry/opentelemetry-ruby-contrib#1653