Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Route name on Traces and Logs #1037

Closed Answered by commonsensesoftware
alefcarlos asked this question in Q&A
Discussion options

I would like to see the version on route instead of v{version:apiVersion} on Traces and Logs. Is there any way ?

For example:

image

The http url does not have the selected version for the endpoint.

You must be logged in to vote

I poked around a bit more and I found this line:

https://github.com/open-telemetry/opentelemetry-dotnet/blob/7dff32480d8b2fe8d41e0958257c00e3602e3b3a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs#L292

This clearly shows that it uses the Endpoint.RoutePattern.RawText as the value. The route template is defined as v{version:apiVersion}/WeatherForecast so that is what I would expect to see. What you would probably prefer is to is IEndpointNameMetadata, which usually maps to OperationId in OpenAPI. There is also IEndpointSummaryMetadata and IEndpointDescriptionMetadata, but those probably provide longer descriptions than what you are looking for.

I don't see an...

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
5 replies
Comment options

Hey, good ?

That package adds an attribute to an specific metric, right ?

But what I mean is the display on traces/logs, it is always v{version:apiVersion}/route-blabla. I think it should be the version.

In my MVC controllers I always use [Route("v{version:apiVersion}/asset-classes")], and it is expected to replace that pattern to the selected version.

Comment options

It emits a metrics giving the latency of each API with API version as a dimension. By attaching a TraceID, you can figure out the API version of the traces.

Comment options

I agree, but this behaviour is expected ? Should not the display be v1/asset-classes on traces titles ?

Comment options

That I don't know. I have only used API version as a query parameter and not in the URL. I plan to play around with Aspire soon.

Comment options

Both Aspire and VS 17. 9 is in preview so I will wait for the release version.

Comment options

Is there no place where the full request URL is shown in the trace? It looks like it is only showing the route template. It's not clear whether that is happening. If the endpoint was hit, then the actual request URL should be the value shown. Unless something else strange is happening in the implementation, I would expect something like order/{id}/items to be shown the same way. Aspire is in preview so there's always the chance this is a bug. I don't know how the values shown in the trace are generated (yet).

You must be logged in to vote
7 replies
Comment options

This looks like it might be for a Minimal API. Is it? It also looks like you want the value of http.target to show up for Activity.DisplayName and http.route. These appear to be showing you your defined route templates. I don't know there is a solution for http.route, but there may be a way to specify an alternate Activity.DisplayName. I would expect the same behavior for any route template that contains parameters; otherwise, something special is happening. That doesn't make sense because the routing system has to match a request to the template. There is no in-between. When you match, you have a template against the request URL, when you don't, you only have the request URL.

Comment options

@commonsensesoftware, this example is a MVC Controller:

 [ApiController]
 [Route("v{version:apiVersion}/[controller]")]
 public class WeatherForecastController(ISampleApiClient sampleApiClient) : ControllerBase
 {
 }

Full trace:

image
Comment options

Comment options

I poked around a bit more and I found this line:

https://github.com/open-telemetry/opentelemetry-dotnet/blob/7dff32480d8b2fe8d41e0958257c00e3602e3b3a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs#L292

This clearly shows that it uses the Endpoint.RoutePattern.RawText as the value. The route template is defined as v{version:apiVersion}/WeatherForecast so that is what I would expect to see. What you would probably prefer is to is IEndpointNameMetadata, which usually maps to OperationId in OpenAPI. There is also IEndpointSummaryMetadata and IEndpointDescriptionMetadata, but those probably provide longer descriptions than what you are looking for.

I don't see any hooks or other approaches to influence the trace and log values so - for now - I don't think there are any solutions. I would recommend creating an issue in the Open Telemetry repo and ask them to honor some of the other available metadata.

Answer selected by alefcarlos
Comment options

I agree as well, I will open an issue there. Thank you for your attention. For now I will remove the pattern from route and explicitly set the version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /