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

Guard against null HttpContext #6792

Merged
merged 5 commits into from
Oct 6, 2022

Conversation

breedx-splk
Copy link
Contributor

Resolves #6787

@breedx-splk breedx-splk requested a review from a team as a code owner September 30, 2022 22:21
@breedx-splk
Copy link
Contributor Author

#6791 should address the test failure.

Copy link
Contributor

@laurit laurit left a comment

Choose a reason for hiding this comment

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

I don't think that this is the best approach. Considering that if the passed HttpContext is null a blank one will be created a few calls deeper we might as well create it here. This would avoid loosing the telemetry that requires access to response.

@breedx-splk
Copy link
Contributor Author

I don't think that this is the best approach.

I will never assert that any change I have ever or will ever make will be the "best".

Considering that if the passed HttpContext is null a blank one will be created a few calls deeper we might as well create it here. This would avoid loosing the telemetry that requires access to response.

I'm not following this. Where does a blank HttpContext get created a few calls deeper? And what kind of response attributes are even useful when the context is null? Isn't it all worthless without context? Where does a null response inhibit other telemetry?

@laurit
Copy link
Contributor

laurit commented Oct 5, 2022

Considering that if the passed HttpContext is null a blank one will be created a few calls deeper we might as well create it here. This would avoid loosing the telemetry that requires access to response.

I'm not following this. Where does a blank HttpContext get created a few calls deeper? And what kind of response attributes are even useful when the context is null? Isn't it all worthless without context? Where does a null response inhibit other telemetry?

See https://github.com/apache/httpcomponents-client/blob/7ab435c271b6ff3bde4e737c2b02ba873ffa8b55/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java#L177 for where http client handles null context.

Try adding null context to

and when you run the test with your modifications you'll see that some tests fail because http.status_code and http.flavor are not filled because they are extracted from the response. Change to @Advice.Argument(value = 3, readOnly = false) HttpContext httpContext and add

      if (httpContext == null) {
        httpContext = new BasicHttpContext();
      }

@breedx-splk
Copy link
Contributor Author

breedx-splk commented Oct 5, 2022

Ok, I think I see where you're coming from. The fact that the client defaults the null httpContext to a BasicHttpContext inside of doExecute() is lost on us, because our instrumentation is sitting above that. Alright, I changed the test code locally to explicitly pass a null context and tried 3 things:

  1. No null guard in WrappedFutureCallback, no defaulting httpContext inClientAdvice.
    Result: test hangs (presumably due to NPE)
  2. Add null guard in WrappedFutureCallback, no defaulting httpContext in ClientAdvice.
    Result: Test failures due to missing http flavor and status code
  3. Add null guard in WrappedFutureCallback, and default httpContext in ClientAdvice.
    Result: Test failures due to number of expected spans being wrong

It's feeling like one of the changes (either test code or instrumentation) is a semantic change. I'm not sure which it is....but explicitly passing in a null context caused the tests to fail before this change and with this change.

If you feel strongly about the null guard being a bad solution, I can close this.

@trask
Copy link
Member

trask commented Oct 6, 2022

  1. Add null guard in WrappedFutureCallback, and default httpContext in ClientAdvice.
    Result: Test failures due to number of expected spans being wrong

@breedx-splk did you maybe miss making the httpContext writable in ClientAdvice?

@Advice.Argument(value = 3, readOnly = false) HttpContext httpContext

@breedx-splk
Copy link
Contributor Author

@breedx-splk did you maybe miss making the httpContext writable in ClientAdvice?

🤦🏻 yes...that was it. Thanks. I'll push a change.

@trask
Copy link
Member

trask commented Oct 6, 2022

@breedx-splk can you rebase? github UI appears to be lying about your change set (at least to me), I've seen this a couple of times recently and rebasing to latest main should hopefully clean it up

…ent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpAsyncClientInstrumentation.java
@trask trask merged commit d9b25d3 into open-telemetry:main Oct 6, 2022
laurit pushed a commit that referenced this pull request Oct 7, 2022
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 23, 2022
Resolves open-telemetry#6787

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 23, 2022
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 31, 2022
Resolves open-telemetry#6787

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 31, 2022
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Dec 4, 2022
Resolves open-telemetry#6787

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Dec 4, 2022
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.

WrappedFutureCallback should handle null HttpContext objects
4 participants