You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to achieve? Following the guidance on enriching spans gets me access to the HttpRequest and HttpResponse objects. I already get a nice normalized URL in the Operation and in the http.route tag, so that is good. There is also an http.path tag that contains the original URL with the route values in them, which sort of works.
But, to make things more queryable it would be nice to store the individual route values as tags. For instance, if I have a REST based endpoint like this:
/api/endpoint/{statecode}/action
I'd like to do queries on my traces like this:
http.route.value.statecode = "HI"
This way I'd be able to carve up the traces based on particular route values as well as look for trends on route values that might have more errors or higher latency.
I can get access to the route values through the HttpResponse object like this:
var routeData = httpResponse.HttpContext.GetRouteData();
From there it is pretty simple to add all the tags to the activity. But is this okay?? The route data is not available on the request object during the ActivityStart event, so I have to wait until the ActivityStop event and grab it off the context object. Not sure if that is safe or not.
Thanks.
The text was updated successfully, but these errors were encountered:
created an extension method and added this to my enrich action:
public static IEnumerable<KeyValuePair<string, object>> GetRoutingTags(this HttpResponse httpResponse)
{
var routeData = httpResponse?.HttpContext?.GetRouteData()
?.Values
?.Select(routeValue => new KeyValuePair<string, object>(routeValue.Key, routeValue.Value));
return routeData;
}
Works a treat, but does require reference to Microsoft.AspNetCore.Routing, which I don't see in the main solution. Suppose I could use reflection to avoid this reference and follow the pattern from HttpInListener for when it pulls the route. Thanks.
Best practice for getting RouteValues and setting them as tags
Describe your environment.
.NET core 3.1 app that exposes REST based API endpoints
Here is my otel initialization:
What are you trying to achieve?
Following the guidance on enriching spans gets me access to the HttpRequest and HttpResponse objects. I already get a nice normalized URL in the Operation and in the http.route tag, so that is good. There is also an http.path tag that contains the original URL with the route values in them, which sort of works.
But, to make things more queryable it would be nice to store the individual route values as tags. For instance, if I have a REST based endpoint like this:
I'd like to do queries on my traces like this:
This way I'd be able to carve up the traces based on particular route values as well as look for trends on route values that might have more errors or higher latency.
I can get access to the route values through the HttpResponse object like this:
From there it is pretty simple to add all the tags to the activity. But is this okay?? The route data is not available on the request object during the ActivityStart event, so I have to wait until the ActivityStop event and grab it off the context object. Not sure if that is safe or not.
Thanks.
The text was updated successfully, but these errors were encountered: