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

[Instrumentation.AspNet] Fix multiple routes of same template in attribute-based routing #2250

Merged
merged 8 commits into from
Nov 18, 2024

Conversation

tchowice
Copy link
Contributor

@tchowice tchowice commented Oct 26, 2024

Changes

ASP.NET instrumentation fails to extract route for attribute-based routing, if multiple HTTP methods use the same route template--a common scenario for RESTful APIs. For example:

public class WidgetsController : ApiController
{
    [Route("api/widgets/{id}")]
    public string Get(int id) {...}

    [Route("api/widgets/{id}")]
    public void Put(int id, [FromBody]string value) {...}

    [Route("api/widgets/{id}")]
    public void Delete(int id) {...}
}

In this case, the MS_Subroutes array will have multiple elements, each corresponding to a different HTTP method.

The original code only extracts the route template if there's only one element in the array. The correct thing to do is to just extract the template from the first subroute, since all subroutes have the same template.

It's not possible for MS_Subroutes array to have different templates in its elements. WebAPI would fail to route and throw an exception, if you declare multiple actions for the same method/template

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@tchowice tchowice requested a review from a team as a code owner October 26, 2024 01:58
Copy link

linux-foundation-easycla bot commented Oct 26, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet label Oct 26, 2024
@Kielek
Copy link
Contributor

Kielek commented Oct 28, 2024

Please sign EasyCLA. It is hard requirement to accept any contribution to this repository.

@tchowice
Copy link
Contributor Author

Please sign EasyCLA. It is hard requirement to accept any contribution to this repository.

Thanks. Working with my company to figure this out.

@CodeBlanch CodeBlanch marked this pull request as draft November 1, 2024 16:27
@tchowice
Copy link
Contributor Author

tchowice commented Nov 6, 2024

Please sign EasyCLA. It is hard requirement to accept any contribution to this repository.

Thanks. Working with my company to figure this out.

@tchowice tchowice closed this Nov 6, 2024
@tchowice
Copy link
Contributor Author

tchowice commented Nov 6, 2024

Please sign EasyCLA. It is hard requirement to accept any contribution to this repository.

Okay, I finally got my company to sign the CLA. Please proceed with reviewing!

@Kielek Kielek reopened this Nov 6, 2024
@Kielek Kielek marked this pull request as ready for review November 6, 2024 17:19
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 14, 2024
@Kielek Kielek removed the Stale label Nov 14, 2024
Copy link
Contributor

@ysolomchenko ysolomchenko left a comment

Choose a reason for hiding this comment

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

Add an entry to the Changelog

Copy link
Contributor

@ysolomchenko ysolomchenko left a comment

Choose a reason for hiding this comment

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

Update the PR title to start with [Instrumentation.AspNet]

@Kielek Kielek changed the title Fix multiple routes of same template in attribute-based routing [Instrumentation.AspNet] Fix multiple routes of same template in attribute-based routing Nov 18, 2024
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.73%. Comparing base (71655ce) to head (ecf7ab3).
Report is 601 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2250      +/-   ##
==========================================
+ Coverage   73.91%   76.73%   +2.81%     
==========================================
  Files         267       15     -252     
  Lines        9615      361    -9254     
==========================================
- Hits         7107      277    -6830     
+ Misses       2508       84    -2424     
Flag Coverage Δ
unittests-Instrumentation.AspNet 76.73% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...on.AspNet/Implementation/HttpRequestRouteHelper.cs 100.00% <100.00%> (ø)

... and 267 files with indirect coverage changes

Copy link
Contributor

@Kielek Kielek left a comment

Choose a reason for hiding this comment

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

@tchowice. Thanks for your contribution. Merging.

@Kielek Kielek merged commit 32bc2ca into open-telemetry:main Nov 18, 2024
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants