sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

Why do Transactions need to have a call to Transaction::finish() - drop(transaction) could do it

Open hetoug opened this issue 3 years ago • 1 comments
trafficstars

I am trying to do performance measuring on parts of a API-server using start_transaction(ctx); This requires calls to transaction.finish() for the transaction-data to be sent to Sentry. Could it not be done when the transaction is dropped by going out of scope as well? Some transactions have multiple exit points - often error-exits by ? - and it is complex trying to mash a transaction.finish() in everywhere.

The change should be quite small - just implementing the Drop trait for trasnaction,, and having the drop(transaction) function calling transaction.finish() - or have I overlooked something.

I am willing to make a PR if that is usefiul.

hetoug avatar Oct 10 '22 19:10 hetoug

The problem here is that the transaction can be attached to the scope as well, either directly or indirectly via spans that hold a reference. The Transaction itself is just an opaque wrapper around an Arc, there could be references to it floating around anywhere.

Apart from this technical limitation, the Sentry "unified API" kinda mandates this API style, even though it admittedly might not be a good fit for Rust.

Swatinem avatar Oct 11 '22 07:10 Swatinem