Skip to content
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

Multiple errors support #1210

Merged
merged 13 commits into from
Jul 29, 2024
Merged

Multiple errors support #1210

merged 13 commits into from
Jul 29, 2024

Conversation

unflxw
Copy link
Contributor

@unflxw unflxw commented Jul 24, 2024

See https://github.com/appsignal/appsignal-agent/pull/1186 for context.

⚠️ The changes in this PR will not work or pass the tests without the changes in the agent PR. You can test these changes as follows:

# Replace this with your target OS+arch
TARGET_OS_ARCH=x86_64-apple-darwin

# Build the agent locally
cd appsignal-agent
git fetch; git checkout extension-transaction-duplication
rake build:target:${TARGET_OS_ARCH}

# Copy the agent build to the integration
for file in appsignal-agent/release/${TARGET_OS_ARCH}/release/*; do
  cp $file appsignal-ruby/ext/
done

# Build the Ruby extension
cd appsignal-ruby/ext
rake extconf.rb && make clean && make

Also see the test setup: appsignal/test-setups#222

A release of the agent containing the changes in the agent PR will be added to this PR before merging.


Support multiple errors per transaction

Implement a new add_error method that allows for multiple errors
to be added to a transaction. These additional errors are stored on
the Ruby transaction object. When the transaction is completed,
duplicate the current transaction to report each of the errors
in its own duplicate transaction.

https://appsignal.slack.com/archives/CNPP953E2/p1720083599598159

Add .duplicate transaction method

Implement support for the appsignal_transaction_duplicate method
implemented in the agent side the extension, in both the Ruby C
extension and the JRuby FFI extension.

Implement a duplicate method for the Transaction class that
calls the extension's own duplicate method to duplicate a
transaction.

Always set error causes when setting errors

This fixes a bug where, when overwriting an already set error by
setting an error that has no error causes, the error causes from the
first error would be kept.

Avoid reporting performance and error sample

When a transaction does not have an error, but it does have one or
more additional errors, instead of reporting the error-less
transaction alongside its duplicates, set the last additional error
as the error for this transaction.

Limit additional errors

Report at most ten additional errors per transaction. If more errors
are provided, report only the last ten additional errors.

Pass the extension as an option when initialising the transaction
object.

Use add_error in report_error helper

Within the report_error helper, use add_error instead of the
set_error method, so that multiple errors can be reported from
the same transaction.

spec/lib/appsignal_spec.rb Outdated Show resolved Hide resolved
spec/lib/appsignal/transaction_spec.rb Outdated Show resolved Hide resolved
@tombruijn
Copy link
Member

You can test these changes as follows

You wrote quite a lengthy set of instructions, but you can also run rake integrations:ruby and test it in the integrations/appsignal-ruby agent submodule.

lib/appsignal/transaction.rb Outdated Show resolved Hide resolved
spec/lib/appsignal/transaction_spec.rb Outdated Show resolved Hide resolved
@unflxw
Copy link
Contributor Author

unflxw commented Jul 25, 2024

✅ on all the above -- will amend the PR tomorrow with #1212 and multiple-errors-aliased in it.

tombruijn and others added 9 commits July 26, 2024 11:24
Implement a new `add_error` method that allows for multiple errors
to be added to a transaction. These additional errors are stored on
the Ruby transaction object. When the transaction is completed,
duplicate the current transaction to report each of the errors
in its own duplicate transaction.

https://appsignal.slack.com/archives/CNPP953E2/p1720083599598159

[skip ci]
Implement support for the `appsignal_transaction_duplicate` method
implemented in the agent side the extension, in both the Ruby C
extension and the JRuby FFI extension.

Implement a `duplicate` method for the `Transaction` class that
calls the extension's own `duplicate` method to duplicate a
transaction.
This fixes a bug where, when overwriting an already set error by
setting an error that has no error causes, the error causes from the
first error would be kept.
When a transaction does not have an error, but it does have one or
more additional errors, instead of reporting the error-less
transaction alongside its duplicates, set the last additional error
as the error for this transaction.
Report at most ten additional errors per transaction. If more errors
are provided, report only the last ten additional errors.

Pass the extension as an option when initialising the transaction
object.
Within the `report_error` helper, use `add_error` instead of the
`set_error` method, so that multiple errors can be reported from
the same transaction.
Test the actual transactions being created, not if we call certain
methods or not.
Test the behavior of the private duplicate method in the complete
method tests that call this private method.
Instead of having `add_error` always add the errors to the additional
errors array, and then "promoting" the last of those errors to an error
in the current transaction later, when the transaction is completed,
do it when an error is first added using `add_error`.

To avoid calls to `set_error` overriding this error instead of adding
a new one, make `set_error` into an alias to `add_error`. Move the
logic to set an error in the transaction into a private `_set_error`
method.
Before this change, the last ten additional errors would be kept,
alongside with the first (non-additional) error. This was a strange
mix of behaviours that would have been hard to document. Instead,
we can now document that we keep the first ten errors.

The language emitted in the warning has been modified to avoid any
mention of "additional" errors.
The agent update and changesets are updated automatically.

[skip review]
Keep all errors in an array, including the first error. Do not add
an error to the errors array if it is already present in the array.
Copy link
Member

@tombruijn tombruijn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@@ -541,8 +537,54 @@ def to_h
end
alias_method :to_hash, :to_h

protected

attr_writer :ext, :is_duplicate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attr_writer :ext, :is_duplicate
attr_writer :is_duplicate

I don't see where this is used. Can we remove it?

@backlog-helper
Copy link


This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

When calling `Appsignal.report_error` with a block, always create
a new transaction when a block is given.
@tombruijn
Copy link
Member

For future Tom and Noemi, and other readers, the last commit comes from this internal discussion (and some messages around that specific thread).

@unflxw unflxw merged commit b31c43c into develop Jul 29, 2024
113 checks passed
@tombruijn tombruijn deleted the multiple-errors branch August 14, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants