Skip to content

fix actix match name bug#539

Merged
Swatinem merged 3 commits into
getsentry:masterfrom
wuerges:fix-actix-match-name-incorrect-match
Jan 24, 2023
Merged

fix actix match name bug#539
Swatinem merged 3 commits into
getsentry:masterfrom
wuerges:fix-actix-match-name-incorrect-match

Conversation

@wuerges

@wuerges wuerges commented Jan 19, 2023

Copy link
Copy Markdown
Contributor

Issue

Actix request.match_name() is buggy.
It doesn't care about the HTTP verb. It only looks at the path. Thus 2 routes with the same path will have the same match name.

Proposal

Previously, format!("{} {}", req.method(), req.uri()) was already used as a fallback for the transaction name.
These changes make it as the default transaction name.

@Swatinem Swatinem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NOTE to self: Axum recently got something similar which we might want to support with a feature flag as well:
https://docs.rs/axum/latest/axum/extract/struct.MatchedPath.html

Comment thread sentry-actix/src/lib.rs Outdated
};
/// Extract a transaction name from the HTTP request
fn transaction_name_from_http(req: &ServiceRequest) -> String {
format!("{} {}", req.method(), req.uri())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe req.uri() might have too high of a cardinality and might even contain PII.

I believe match_pattern is the thing we want, is it documented to give you /user/{id}/profile for example: https://docs.rs/actix-web/latest/actix_web/struct.HttpRequest.html#method.match_pattern

match_name seems to refer to the function used for logging? Not sure, there is no example.

Adding a req.method() prefix does seem like a very good thing indeed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree 100%.

I've changed the code to use request.match_pattern(), fixed the broken tests and added an extra one that does a POST with a pattern.

Comment thread sentry-actix/src/lib.rs Outdated
@codecov

codecov Bot commented Jan 24, 2023

Copy link
Copy Markdown

Codecov Report

Merging #539 (2b709e1) into master (2001144) will increase coverage by 0.14%.
The diff coverage is 97.14%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #539      +/-   ##
==========================================
+ Coverage   70.73%   70.87%   +0.14%     
==========================================
  Files          66       66              
  Lines        6601     6626      +25     
==========================================
+ Hits         4669     4696      +27     
+ Misses       1932     1930       -2     

@Swatinem Swatinem enabled auto-merge (squash) January 24, 2023 08:55
@Swatinem Swatinem merged commit be5dfb2 into getsentry:master Jan 24, 2023
@Swatinem Swatinem mentioned this pull request Jan 31, 2023
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