-
Notifications
You must be signed in to change notification settings - Fork 1k
make apache httpclient instrumentations indy-ready #13895
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b0ec59e
apache httpclient indy-ready
SylvainJuge 68bcc0a
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 5ccac8f
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge a12b322
post-review cleanup
SylvainJuge 0627a7d
add missing @Nullable annotations
SylvainJuge 03766b2
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge b678d5d
./gradlew spotlessApply
otelbot[bot] 0e14a5c
fix hard to spot typo
SylvainJuge 75016df
make fields final in AdviceScope
SylvainJuge d69e595
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 7b3d023
post-review cleanup
SylvainJuge 458c6ac
remove another copy of ApacheHttpClientHelper
SylvainJuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
...opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientHelper.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,15 @@ | |
| import io.opentelemetry.context.Scope; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import javax.annotation.Nullable; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.asm.Advice.AssignReturned; | ||
| import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.apache.http.HttpHost; | ||
| import org.apache.http.HttpRequest; | ||
| import org.apache.http.HttpResponse; | ||
| import org.apache.http.client.ResponseHandler; | ||
| import org.apache.http.client.methods.HttpUriRequest; | ||
|
|
||
|
|
@@ -123,171 +127,145 @@ public void transform(TypeTransformer transformer) { | |
| this.getClass().getName() + "$RequestWithHandlerAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class UriRequestAdvice { | ||
| public static class AdviceScope { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] this |
||
| private final ApacheHttpClientRequest otelRequest; | ||
| private final Context parentContext; | ||
| private final Context context; | ||
| private final Scope scope; | ||
|
|
||
| private AdviceScope( | ||
| ApacheHttpClientRequest otelRequest, Context parentContext, Context context, Scope scope) { | ||
| this.otelRequest = otelRequest; | ||
| this.parentContext = parentContext; | ||
| this.context = context; | ||
| this.scope = scope; | ||
| } | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void methodEnter( | ||
| @Advice.Argument(0) HttpUriRequest request, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| @Nullable | ||
| public static AdviceScope start(ApacheHttpClientRequest otelRequest) { | ||
| Context parentContext = currentContext(); | ||
| if (!instrumenter().shouldStart(parentContext, otelRequest)) { | ||
| return null; | ||
| } | ||
| Context context = instrumenter().start(parentContext, otelRequest); | ||
| return new AdviceScope(otelRequest, parentContext, context, context.makeCurrent()); | ||
| } | ||
|
|
||
| otelRequest = new ApacheHttpClientRequest(request); | ||
| public <T> ResponseHandler<T> wrapHandler(ResponseHandler<T> handler) { | ||
| return new WrappingStatusSettingResponseHandler<>( | ||
| context, parentContext, otelRequest, handler); | ||
| } | ||
|
|
||
| if (!instrumenter().shouldStart(parentContext, otelRequest)) { | ||
| return; | ||
| public void end(@Nullable Object result, @Nullable Throwable throwable) { | ||
| scope.close(); | ||
| if (throwable != null) { | ||
| instrumenter().end(context, otelRequest, null, throwable); | ||
| } else if (result instanceof HttpResponse) { | ||
| instrumenter().end(context, otelRequest, (HttpResponse) result, null); | ||
| } | ||
| // ended in WrappingStatusSettingResponseHandler | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class UriRequestAdvice { | ||
|
|
||
| context = instrumenter().start(parentContext, otelRequest); | ||
| scope = context.makeCurrent(); | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static AdviceScope methodEnter(@Advice.Argument(0) HttpUriRequest request) { | ||
| return AdviceScope.start(new ApacheHttpClientRequest(request)); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void methodExit( | ||
| @Advice.Argument(0) HttpUriRequest request, | ||
| @Advice.Return Object result, | ||
| @Advice.Thrown Throwable throwable, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| @Advice.Return @Nullable Object result, | ||
| @Advice.Thrown @Nullable Throwable throwable, | ||
| @Advice.Enter @Nullable AdviceScope adviceScope) { | ||
|
|
||
| scope.close(); | ||
| ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable); | ||
| if (adviceScope != null) { | ||
| adviceScope.end(result, throwable); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class UriRequestWithHandlerAdvice { | ||
|
|
||
| @AssignReturned.ToArguments(@ToArgument(value = 1, index = 1)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void methodEnter( | ||
| public static Object[] methodEnter( | ||
| @Advice.Argument(0) HttpUriRequest request, | ||
| @Advice.Argument(value = 1, readOnly = false) ResponseHandler<?> handler, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| Context parentContext = currentContext(); | ||
|
|
||
| otelRequest = new ApacheHttpClientRequest(request); | ||
|
|
||
| if (!instrumenter().shouldStart(parentContext, otelRequest)) { | ||
| return; | ||
| } | ||
|
|
||
| context = instrumenter().start(parentContext, otelRequest); | ||
| scope = context.makeCurrent(); | ||
| @Advice.Argument(1) ResponseHandler<?> handler) { | ||
|
|
||
| AdviceScope adviceScope = AdviceScope.start(new ApacheHttpClientRequest(request)); | ||
| // Wrap the handler so we capture the status code | ||
| if (handler != null) { | ||
| handler = | ||
| new WrappingStatusSettingResponseHandler<>( | ||
| context, parentContext, otelRequest, handler); | ||
| } | ||
| return new Object[] { | ||
| adviceScope, adviceScope == null ? handler : adviceScope.wrapHandler(handler) | ||
| }; | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void methodExit( | ||
| @Advice.Argument(0) HttpUriRequest request, | ||
| @Advice.Return Object result, | ||
| @Advice.Thrown Throwable throwable, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| @Advice.Enter Object[] enterResult) { | ||
|
|
||
| scope.close(); | ||
| ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable); | ||
| AdviceScope adviceScope = (AdviceScope) enterResult[0]; | ||
| if (adviceScope != null) { | ||
| adviceScope.end(result, throwable); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class RequestAdvice { | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void methodEnter( | ||
| @Advice.Argument(0) HttpHost host, | ||
| @Advice.Argument(1) HttpRequest request, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| Context parentContext = currentContext(); | ||
|
|
||
| otelRequest = new ApacheHttpClientRequest(host, request); | ||
|
|
||
| if (!instrumenter().shouldStart(parentContext, otelRequest)) { | ||
| return; | ||
| } | ||
|
|
||
| context = instrumenter().start(parentContext, otelRequest); | ||
| scope = context.makeCurrent(); | ||
| public static AdviceScope methodEnter( | ||
| @Advice.Argument(0) HttpHost host, @Advice.Argument(1) HttpRequest request) { | ||
| return AdviceScope.start(new ApacheHttpClientRequest(host, request)); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void methodExit( | ||
| @Advice.Return Object result, | ||
| @Advice.Thrown Throwable throwable, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| @Advice.Enter AdviceScope adviceScope) { | ||
|
|
||
| scope.close(); | ||
| ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable); | ||
| if (adviceScope != null) { | ||
| adviceScope.end(result, throwable); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class RequestWithHandlerAdvice { | ||
|
|
||
| @AssignReturned.ToArguments(@ToArgument(value = 2, index = 1)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void methodEnter( | ||
| public static Object[] methodEnter( | ||
| @Advice.Argument(0) HttpHost host, | ||
| @Advice.Argument(1) HttpRequest request, | ||
| @Advice.Argument(value = 2, readOnly = false) ResponseHandler<?> handler, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| Context parentContext = currentContext(); | ||
|
|
||
| otelRequest = new ApacheHttpClientRequest(host, request); | ||
|
|
||
| if (!instrumenter().shouldStart(parentContext, otelRequest)) { | ||
| return; | ||
| } | ||
|
|
||
| context = instrumenter().start(parentContext, otelRequest); | ||
| scope = context.makeCurrent(); | ||
|
|
||
| // Wrap the handler so we capture the status code | ||
| if (handler != null) { | ||
| handler = | ||
| new WrappingStatusSettingResponseHandler<>( | ||
| context, parentContext, otelRequest, handler); | ||
| } | ||
| @Advice.Argument(2) ResponseHandler<?> handler) { | ||
|
|
||
| AdviceScope adviceScope = AdviceScope.start(new ApacheHttpClientRequest(host, request)); | ||
| return new Object[] { | ||
| adviceScope, | ||
| // Wrap the handler so we capture the status code | ||
| adviceScope == null ? handler : adviceScope.wrapHandler(handler) | ||
| }; | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void methodExit( | ||
| @Advice.Return Object result, | ||
| @Advice.Thrown Throwable throwable, | ||
| @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| @Advice.Enter Object[] enterResult) { | ||
|
|
||
| scope.close(); | ||
| ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable); | ||
| AdviceScope adviceScope = (AdviceScope) enterResult[0]; | ||
| if (adviceScope != null) { | ||
| adviceScope.end(result, throwable); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.