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

Add Performance Monitoring (transactions) support #59

Merged
merged 21 commits into from
Nov 16, 2023
Merged

Conversation

Hugo-C
Copy link
Contributor

@Hugo-C Hugo-C commented Sep 17, 2023

Hello, this PR add support for performance/transaction.
It requires sentry_transaction_sample_rate to be set with a value above 0, else transactions are not enabled.

A downside is that raw URI are used and so for a common route (with an id as parameter for example), transaction will not be aggregated. To fix it, we need to set the transaction name in the on_response callback as the routing is not yet done in on_request. But I didn't find a way to set a name to an existing transaction.
A solution might be to start a span in the on_request and then create later the transaction with sentry::continue_from_span. I didn't test it though.

Anyway let me know your thoughts and if there is anything you would like I change.

@intgr
Copy link
Owner

intgr commented Oct 22, 2023

Hi! Thanks for the contribution. Sorry, the notification about this PR got lost among others.

This expands the scope of rocket-sentry beyond what I need it for (some background here). My knowledge of neither Rust nor Sentry are that strong.

Would you be interested in taking over the maintainership of this crate? I can still continue as a co-maintainer and help with reviews, if you want.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +168 to +172
fn request_to_transaction_name(request: &Request) -> String {
let method = request.method();
let path = request.uri().path();
format!("{method} {path}")
Copy link
Owner

Choose a reason for hiding this comment

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

I imagine users may want to customize the transaction name. So possibly as a follow-up, it may make sense to provide a "request to transaction name" hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how it would looks like but nice idea. Some sentry sdk propose out of the box for transactions names to be returned as url or endpoint/function name. A custom hook could accomplish the same thing.

@intgr
Copy link
Owner

intgr commented Oct 22, 2023

A downside is that raw URI are used and so for a common route (with an id as parameter for example), transaction will not be aggregated. To fix it, we need to set the transaction name in the on_response callback as the routing is not yet done in on_request. But I didn't find a way to set a name to an existing transaction.

A solution might be to start a span in the on_request and then create later the transaction with sentry::continue_from_span. I didn't test it though.

I agree, that's worth trying out and fixing.

But feel free to leave it to a follow-up PR.

@intgr
Copy link
Owner

intgr commented Oct 22, 2023

Also README needs updating, this is no longer true:

Currently rocket-sentry is very basic, it only enables the Rust panic handler.
There is no integration with the Rocket request lifecycle.

  • We should document which Transaction fields we fill.

src/lib.rs Outdated Show resolved Hide resolved
@Hugo-C
Copy link
Contributor Author

Hugo-C commented Oct 23, 2023

Hi! Thanks for the contribution. Sorry, the notification about this PR got lost among others.

This expands the scope of rocket-sentry beyond what I need it for (some background here). My knowledge of neither Rust nor Sentry are that strong.

Would you be interested in taking over the maintainership of this crate? I can still continue as a co-maintainer and help with reviews, if you want.

Hi, thanks for taking the time to review the PR.
I would gladly help maintaining the crate although I am not very proficient in Rust. But let's first try to merge this PR 😃 .

Also README needs updating, this is no longer true:

Currently rocket-sentry is very basic, it only enables the Rust panic handler.
There is no integration with the Rocket request lifecycle.

* [ ]  We should document which `Transaction` fields we fill.

I tried to list the transaction's fields. Let me know what you think of the changes.

@Hugo-C
Copy link
Contributor Author

Hugo-C commented Nov 5, 2023

@intgr I have added headers as well as I have the need for it.
Once everything is good for you, I should probably squash the commits in a single one.

Copy link
Owner

@intgr intgr left a comment

Choose a reason for hiding this comment

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

Sorry for so many rounds of back-and-forth, I don't feel very competent reviewing this stuff yet. :)

Once everything is good for you, I should probably squash the commits in a single one.

No need, I'll use GitHub's "squash and merge"

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
Hugo-C and others added 2 commits November 6, 2023 22:46
Co-authored-by: Marti Raudsepp <marti@juffo.org>
@intgr intgr changed the title Add performance support Add Performance Monitoring (transactions) support Nov 16, 2023
Copy link
Owner

@intgr intgr left a comment

Choose a reason for hiding this comment

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

Thanks, looks good! Sorry again for procrastinating on this.

@intgr intgr merged commit aa4df5a into intgr:master Nov 16, 2023
1 check passed
@Hugo-C
Copy link
Contributor Author

Hugo-C commented Nov 17, 2023

Great ! Don't forget to release it on crates.io, so I can switch back to using the crate. Cheers!

@intgr
Copy link
Owner

intgr commented Nov 19, 2023

@Hugo-C It's released! https://github.com/intgr/rocket-sentry/releases/tag/v0.16.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants