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

MS_SubRoutes are not affecting Transaction names. #1176

Closed
kszymanski opened this issue Feb 15, 2021 · 7 comments · Fixed by #1189
Closed

MS_SubRoutes are not affecting Transaction names. #1176

kszymanski opened this issue Feb 15, 2021 · 7 comments · Fixed by #1189
Labels
agent-dotnet bug Something isn't working

Comments

@kszymanski
Copy link

APM Agent version

The version of the Elastic.Apm nuget package used: master branch directly, AspNetFullFrameworkSampleApp

Environment

Operating system and version: Windows Version 10.0.19042.804

.NET Framework/Core name and version (e.g. .NET 4.6.1, NET Core 3.1.100) : .NET 4.6.1

Application Target Framework(s) (e.g. net461, netcoreapp3.1): net461

Describe the bug

Transaction names are generated from request.Unvalidated.Path for WebApi routes that have [Route] attribute on it.

To Reproduce

Steps to reproduce the behavior:

  1. Use AspNetFullFrameworkSampleApp from master branch (set default apm and kibana from for example Quick start guide
  2. Find AspNetFullFrameworkSampleApp.Controllers.WebApiController
  3. Add this sample controller method:
[RoutePrefix("api/webapi")]
public class WebApiController : ApiController
{
	...
	[HttpGet]
	[Route("{someId}")]
	public IHttpActionResult AskMe(Guid someId) => Ok($"This is an example response from a web api controller: {someId}");
	...
  1. Launch AspNetFullFrameworkSampleApp
  2. Use for example postman to request endpoint with dummy guid:
    image
  3. Find call in Kibana APM

Expected behavior

Transaction name is taken from subroute route template.
image
Example fix would be in Elastic.Apm.Model.Transaction.GetNameFromRouteContext(IDictionary<string, object> routeValues) you can add another if statement (around line 546):

else if (routeValues.TryGetValue("MS_SubRoutes", out var template))
{
	var subroute = ((IEnumerable<IHttpRouteData>)template).FirstOrDefault();
	if(subroute != null)
	{
		name = subroute.Route.RouteTemplate;
	}
}

Actual behavior

Guid is used as transaction name:
image

@kszymanski kszymanski added the bug Something isn't working label Feb 15, 2021
@russcam
Copy link
Contributor

russcam commented Feb 18, 2021

Thanks for opening @kszymanski. This seems like a reasonable change to include

russcam added a commit to russcam/apm-agent-dotnet that referenced this issue Feb 19, 2021
This commit updates ElasticApmModule to get the transaction
name for a Web API controller routed with attribute routing
from the "MS_SubRoutes" route data value.

A delegate to get the template from IHttpRouteData when
System.Web.Http is referenced.

Closes elastic#1176
@kszymanski
Copy link
Author

Thank you @russcam! Looking forward to 1.9.0 release!

@insanity13
Copy link

@kszymanski Could you tell me why RouteData might be empty?
Route Attrubute:
image

Request URL:
image

Route Data:
image

@russcam
Copy link
Contributor

russcam commented Feb 23, 2021

@insanity13 the RouteData looks like one that's associated with an MVC controller (System.Web.Routing.RouteData) and not one associated with a Web API controller (System.Web.Http.Routing.HttpRouteData). Does the controller derive from System.Web.Http.ApiController and are attribute routes registered with HttpConfiguration? e.g.

@insanity13
Copy link

insanity13 commented Feb 23, 2021

Does the controller derive from System.Web.Http.ApiController

Yes, all API-contrillers derive from System.Web.Http.ApiController:
image

and are attribute routes registered with HttpConfiguration

Yes, we are call MapHttpAttributeRoutes()

@kszymanski
Copy link
Author

kszymanski commented Feb 23, 2021

@insanity13 I'm sorry but I don't know why. I had myself a problem with Route attribute and APM that did not see correct route name so I debug it and google around. That is how I found article about MS_SubRoutes. I also noticed RoutePrefix attribute is making a difference some times.

@insanity13
Copy link

Unfortunately, I have not found a way to get information about the route in my case (in Request End).

  • .NET 4.7.2
  • ASP.NET Web App using OWIN Startup
    • System.Web.Http.Owin, Version=5.2.7
    • Microsoft.AspNet.WebApi, Version=5.2.7

Found only one option: to register the ActionFilter and get a template from ControllerContext. In this place, the template is correct.

russcam added a commit to russcam/apm-agent-dotnet that referenced this issue Mar 8, 2021
This commit updates ElasticApmModule to get the transaction
name for a Web API controller routed with attribute routing
from the "MS_SubRoutes" route data value.

A delegate to get the template from IHttpRouteData when
System.Web.Http is referenced.

Closes elastic#1176
russcam added a commit that referenced this issue Mar 9, 2021
This commit updates ElasticApmModule to get the transaction
name for a Web API controller routed with attribute routing
from the "MS_SubRoutes" route data value.

A delegate to get the template from IHttpRouteData when
System.Web.Http is referenced.

Closes #1176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-dotnet bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants