-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add a way to get the template for the current request #1191
Comments
Thanks @Azquelt. Unless there is some other way to get this information in a sub-resource scenario, perhaps ResourceInfo should have a |
@Azquelt Seems like a useful addition. Simple cases should be possible today with some introspection, at least those without resource locators. @jim-krueger I agree. However, such a method would require creating a new instance of @jansupol Any concerns from an implementation point of view? |
I just want to add a +1 to this. It's come up for WildFly before as well and the workarounds aren't ideal as they usually rely on implementation details. |
@Azquelt Should |
@jansupol For my use case yes, I would want to include both the ApplicationPath and any context root. I don't have a strong opinion as to whether that should be returned from the API, as long as it's possible for someone to construct the full template including the application path and context root. |
This sounds like a useful addition, but regarding your original use case I wonder if the route really is the template. Isn't it the actual resource? |
I'm not sure what you mean by "the actual resource" here. The concept of the "route" is defined by the OpenTelemetry Specification as the path template (in whatever format is used by the server framework). I'm asking for a portable way to get that information from Jakarta REST. |
I am +1 for this, but we need to find a proper name for this. Right I can see the following suggestions:
|
I think I like "request template" best, however I do question if that doesn't fit an "@ApplicationPath". In which case, I guess "path template" might make the most sense. I have no real strong preference though. |
The resource is With the actual value ( |
That's a good point on "path" vs "template". I guess to me something like |
It sounds strange, but a template is even a template if it does not contain any placeholders at all. So we can call it |
This makes the most sense to me then. |
I couldn't find a way to get the full template used to match the current request against a rest resource.
Background
I'm working on support for MicroProfile OpenTelemetry, which integrates with Jakarta Rest to automatically create traces when rest requests are served. These traces can be aggregated from many microservices so that you can look at one incoming request and see all the microservices which were involved in serving the response.
One of the suggested pieces of information to add to each trace is what they call the "route":
So, for example, if I had this resource:
For a request to
/foo/12345
, I'd want to use the string/foo/{id}
as the value forhttp.route
. (Assuming an application path of/
)Storing this information allows me to search all the aggregated traces and find ones which involved a request to this endpoint. For Jakarta REST, I think it's usually equivalent to the class + method pair used to serve the request, but conceptually, the idea of the path template is more easily understandable and applicable across different languages and frameworks.
Problem
Although this is information which any Jakarta Rest implementation needs to process to serve a request, I couldn't find a way for an application or a filter to get or to reliably construct this string using the API.
For a simple case where only one resource class is involved, I can inject
ResourceInfo
to get the class and method and use reflection to look at the@Path
annotations on both, but this approach doesn't work if sub-resources are used to serve the request.Would it be possible to add to the API a way to get the template used to serve the current request, or expose the information needed to reconstruct it? I think this could be done by either:
UriInfo
to get the template directlyResourceInfo
so that if a request is served by a subresource, then information about preceding resource locators is also availableThe text was updated successfully, but these errors were encountered: