Skip to content

Caught AR validation errors are resulting in error spans #1459

Open
@renchap

Description

@renchap

Our app uses ActiveRecord validations (example), and uses some create! calls in the code (example controller action, and create!).

Then a record fails the validation, an exception is thrown, and is then caught and returned as an HTTP error, with the failed validations in the body (here).

This causes the OTEL instrumentation to generate traces where the User.create! span has an error attached, but the root span does not:

Image

This causes tools like Sentry or Datadog to create a new entry in their error tracking system, even if everything is handled in the app and the error is not actionable.

Using exceptions for such control flow is a common pattern in Rails, and as an application developer or operator, I expect that errors are things that needs to be reviewed and fixed, which is not the case here.

Note: there is a relevant discussion in the Slack channel

Possible discussed solutions are marking some exceptions (such as ActiveRecord::RecordInvalid or ActiveRecord:: RecordNotFound) as non-exceptional in the AR Validations instrumentation, or having a setting to prevent those spans to be errors entirely, allowing the app developer to explicitly indicate that those exceptions are handled correctly by the app (and if thats not the case, the root span should be an error anyway).

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededinstrumentationkeepEnsures stale-bot keeps this issue/PR open

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions