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

Capture servlet request parameters #4703

Merged

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Nov 24, 2021

This pr implements capturing HTTP request parameters as span attributes when request is handled by servlet api. Similarly to capturing HTTP headers only parameters that are explicitly configured will be captured.

@laurit laurit force-pushed the capture-servlet-request-parameters branch from 93f1823 to 663fb45 Compare November 24, 2021 18:19
@@ -16,6 +16,9 @@ class JettyServletHandlerTest extends AbstractServlet5Test<Object, Object> {

@Override
String expectedServerSpanName(ServerEndpoint endpoint) {
if (ServerEndpoint.CAPTURE_PARAMETERS == endpoint) {
return "HTTP POST"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this request have to be POST?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't. I chose POST because GET parameters can be extracted from url and could also be captured on other http server frameworks. POST parameters, in contrast, are easy to capture with servlet api, but hard on all other http server frameworks. This is also the reason why it is only implemented for servlet.

Copy link
Member

Choose a reason for hiding this comment

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

How important is it to capture parameters from application/x-www-form-urlencoded bodies vs limiting this feature to query parameters?

I think the application/x-www-form-urlencoded body support makes this feature harder to explain to users and (as you mentioned) harder to implement across all http server frameworks. I think it may also make this feature harder to upstream into the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that from end users perspective it makes sense to capture a request parameter regardless of whether it was passed in url, post or in multipart request, because the same parameter could be passed by different means even in the same application. I suspect that it will be hard to explain why we capture a parameter only when it is passed in the url if we choose to ignore post parameters. Whilst it might be hard to get access to post or multipart parameters in most http server frameworks it would require addition effort to exclude these using servlet api.
I agree that specifying this will be hard because with some languages and frameworks it might be too hard to capture post parameters, while in other it will be easy and excluding them just to implement the feature the same way across languages and frameworks will feel wrong. If this is going to be specified it will need to allow flexibility to allow capturing extra info when it is available and not force capturing post parameters where it is hard.

Copy link
Member

Choose a reason for hiding this comment

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

What do you think of renaming from "request parameters" to "query parameters"? (and still applying to both query strings and application/x-www-form-urlencoded bodies)

For some reason, when I see "request parameters", I'm not really sure what that means.

Though, I just went looking and I'm having a hard time finding a canonical definition for either "request parameter" or "query parameter" 😭 🤷‍♂️.

(I can live with "request parameters" if that's what others prefer, and of course the spec will have the last word on the naming..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spring mvc uses @RequestParam. JAX-RS has @QueryParam (for parameters in query string) and @FormParam (for post).

Copy link
Member

Choose a reason for hiding this comment

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

thx, let's merge as is 👍

@trask trask merged commit 61b0dd3 into open-telemetry:main Dec 6, 2021
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Capture servlet request parameters

* use concurrenthashmap for cache
@laurit laurit deleted the capture-servlet-request-parameters branch July 6, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants