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

AWS SDK instrumentation: HTTP POST body included in Span http.url #8956

Closed
semonte opened this issue Jul 16, 2023 · 3 comments
Closed

AWS SDK instrumentation: HTTP POST body included in Span http.url #8956

semonte opened this issue Jul 16, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@semonte
Copy link

semonte commented Jul 16, 2023

AWS SDK may use query parameters to populate an AWS SDK request's data. For example, the SesAsyncClient's sendEmail method adds various email attributes as query parameters (e.g. email subject and email body) using the QueryProtocolMarshaller. Before dispatching the actual HTTP request the AWS SDK moves the query parameters to HTTP body using the QueryParametersToBodyInterceptor. Thus, the initial query parameter data is included in the POST body instead of the URL in the end.

This has an undesirable side effect with the OpenTelementry agent. The instrumented AWS SDK calls the SdkHttpRequest getUri method, which returns the initial query parameters, to populate a Span's http.url attribute. This results in Spans that include email content and other POST body data in the http.url attribute.

Steps to reproduce
The issue can be reproduced by running the following code with OpenTelemetry Java agent.

final SesAsyncClient sesAsyncClient = SesAsyncClient.builder().build();

final SendEmailRequest request = SendEmailRequest
    .builder()
    .message(
        Message
            .builder()
            .subject(Content.builder().data("test subject").build())
            .body(Body.builder().text(Content.builder().data("test text").build()).build())
            .build()
    )
    .build();

sesAsyncClient.sendEmail(request).get();

Observe that the http.url attribute has the following value:

https://email.us-east-1.amazonaws.com?Action=SendEmail&Version=2010-12-01&Message.Subject.Data=test%20subject&Message.Body.Text.Data=test%20text

What did you expect to see?
The span to contain http.url with value https://email.us-east-1.amazonaws.com.

What did you see instead?
The Span's http.url containing value https://email.us-east-1.amazonaws.com?Action=SendEmail&Version=2010-12-01&Message.Subject.Data=test%20subject&Message.Body.Text.Data=test%20text

I propose that an additional check is added in AWS SDK instrumentation when the request URL is resolved.

@Override
public String getUrl(ExecutionAttributes request) {
    SdkHttpRequest httpRequest = request.getAttribute(TracingExecutionInterceptor.SDK_HTTP_REQUEST_ATTRIBUTE);
    
    if (queryParametersMovedToBody(request)) {
        return stripQueryParameters(httpRequest.getUri()).toString();
    }
    
    return httpRequest.getUri().toString();
}
@semonte semonte added the bug Something isn't working label Jul 16, 2023
@mateuszrzeszutek
Copy link
Member

Related issue: #8453

@rapphil
Copy link
Contributor

rapphil commented Jul 17, 2023

Hi, this PR included in the OpenTelemetry instrumentation for Java 1.28.0 solves this issue: #8931

(Please take a look into the Unit tests added)

@semonte
Copy link
Author

semonte commented Jul 17, 2023

This is great news, thank you! I'll close this bug then.

@semonte semonte closed this as completed Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants