- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1k
 
make reactor indy-ready #14640
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
make reactor indy-ready #14640
Changes from 17 commits
fd5b57a
              9af07a0
              7909a4d
              3864cf9
              23c60ef
              2adabdc
              c77fbaa
              8bf8799
              68d6de6
              e8c19d3
              19b4d17
              c3c7bc6
              6d33fba
              0295a3d
              64356d4
              97251a4
              4b84743
              7689543
              dc30462
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -17,6 +17,8 @@ | |
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import java.util.function.BiConsumer; | ||
| 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 reactor.netty.Connection; | ||
| 
          
            
          
           | 
    @@ -74,92 +76,111 @@ public void transform(TypeTransformer transformer) { | |
| public static class CreateAdvice { | ||
| 
     | 
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter(@Advice.Local("otelCallDepth") CallDepth callDepth) { | ||
| callDepth = CallDepth.forClass(HttpClient.class); | ||
| public static CallDepth onEnter() { | ||
| CallDepth callDepth = CallDepth.forClass(HttpClient.class); | ||
| callDepth.getAndIncrement(); | ||
| return callDepth; | ||
| } | ||
| 
     | 
||
| @AssignReturned.ToReturned | ||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void stopSpan( | ||
| public static HttpClient stopSpan( | ||
| @Advice.Thrown Throwable throwable, | ||
| @Advice.Return(readOnly = false) HttpClient client, | ||
| @Advice.Local("otelCallDepth") CallDepth callDepth) { | ||
| @Advice.Return HttpClient client, | ||
| @Advice.Enter CallDepth callDepth) { | ||
| 
     | 
||
| if (callDepth.decrementAndGet() == 0 && throwable == null) { | ||
| client = client.doOnRequest(new OnRequest()).mapConnect(new MapConnect()); | ||
| return client.doOnRequest(new OnRequest()).mapConnect(new MapConnect()); | ||
| } | ||
| return client; | ||
| } | ||
| } | ||
| 
     | 
||
| @SuppressWarnings("unused") | ||
| public static class OnRequestAdvice { | ||
| 
     | 
||
| @AssignReturned.ToArguments(@ToArgument(0)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.Argument(value = 0, readOnly = false) | ||
| BiConsumer<? super HttpClientRequest, ? super Connection> callback) { | ||
| public static BiConsumer<? super HttpClientRequest, ? super Connection> onEnter( | ||
| @Advice.Argument(0) BiConsumer<? super HttpClientRequest, ? super Connection> callback) { | ||
| if (DecoratorFunctions.shouldDecorate(callback.getClass())) { | ||
| callback = new DecoratorFunctions.OnRequestDecorator(callback); | ||
| return new DecoratorFunctions.OnRequestDecorator(callback); | ||
| } | ||
| return callback; | ||
| } | ||
| } | ||
| 
     | 
||
| @SuppressWarnings("unused") | ||
| public static class OnRequestErrorAdvice { | ||
| 
     | 
||
| @AssignReturned.ToArguments(@ToArgument(0)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.Argument(value = 0, readOnly = false) | ||
| BiConsumer<? super HttpClientRequest, ? super Throwable> callback) { | ||
| public static BiConsumer<? super HttpClientRequest, ? super Throwable> onEnter( | ||
| @Advice.Argument(0) BiConsumer<? super HttpClientRequest, ? super Throwable> callback) { | ||
| if (DecoratorFunctions.shouldDecorate(callback.getClass())) { | ||
| callback = new DecoratorFunctions.OnRequestErrorDecorator(callback); | ||
| return new DecoratorFunctions.OnRequestErrorDecorator(callback); | ||
| } | ||
| return callback; | ||
| } | ||
| } | ||
| 
     | 
||
| @SuppressWarnings("unused") | ||
| public static class OnResponseAdvice { | ||
| 
     | 
||
| @AssignReturned.ToArguments(@ToArgument(0)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.Argument(value = 0, readOnly = false) | ||
| BiConsumer<? super HttpClientResponse, ? super Connection> callback, | ||
| public static BiConsumer<? super HttpClientResponse, ? super Connection> onEnter( | ||
| @Advice.Argument(0) BiConsumer<? super HttpClientResponse, ? super Connection> callback, | ||
| @Advice.Origin("#m") String methodName) { | ||
| if (DecoratorFunctions.shouldDecorate(callback.getClass())) { | ||
| boolean forceParentContext = methodName.equals("doAfterResponse"); | ||
| callback = new DecoratorFunctions.OnResponseDecorator(callback, forceParentContext); | ||
| return new DecoratorFunctions.OnResponseDecorator(callback, forceParentContext); | ||
| } | ||
| return callback; | ||
| } | ||
| } | ||
| 
     | 
||
| @SuppressWarnings("unused") | ||
| public static class OnResponseErrorAdvice { | ||
| 
     | 
||
| @AssignReturned.ToArguments(@ToArgument(0)) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.Argument(value = 0, readOnly = false) | ||
| BiConsumer<? super HttpClientResponse, ? super Throwable> callback) { | ||
| public static BiConsumer<? super HttpClientResponse, ? super Throwable> onEnter( | ||
| @Advice.Argument(0) BiConsumer<? super HttpClientResponse, ? super Throwable> callback) { | ||
| if (DecoratorFunctions.shouldDecorate(callback.getClass())) { | ||
| callback = new DecoratorFunctions.OnResponseErrorDecorator(callback); | ||
| return new DecoratorFunctions.OnResponseErrorDecorator(callback); | ||
| } | ||
| return callback; | ||
| } | ||
| } | ||
| 
     | 
||
| @SuppressWarnings("unused") | ||
| public static class OnErrorAdvice { | ||
| 
     | 
||
| @AssignReturned.ToArguments({ | ||
| @ToArgument(value = 0, index = 0), | ||
| @ToArgument(value = 1, index = 1) | ||
| }) | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter( | ||
| @Advice.Argument(value = 0, readOnly = false) | ||
| BiConsumer<? super HttpClientRequest, ? super Throwable> requestCallback, | ||
| @Advice.Argument(value = 1, readOnly = false) | ||
| BiConsumer<? super HttpClientResponse, ? super Throwable> responseCallback) { | ||
| public static Object[] onEnter( | ||
| @Advice.Argument(0) | ||
| BiConsumer<? super HttpClientRequest, ? super Throwable> originalRequestCallback, | ||
| @Advice.Argument(1) | ||
| BiConsumer<? super HttpClientResponse, ? super Throwable> originalResponseCallback) { | ||
| 
     | 
||
| // intermediate variables needed for inlined instrumentation | ||
| 
         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. was there some side effect that surfaced that caused issues with referencing the originals without making an intermediate? 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. Yes, when removing those this makes the tests fail with missing spans. I remember having seen this elsewhere and thus applied this workaround after spending too much time doing diffs and partial reverts. It could be something worth investigating further as it might be related to bytebuddy or the way we use it. 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. as far as I remember byte-buddy does not allow you to reassign a value to a read only argument  | 
||
| BiConsumer<? super HttpClientRequest, ? super Throwable> requestCallback = | ||
| originalRequestCallback; | ||
| BiConsumer<? super HttpClientResponse, ? super Throwable> responseCallback = | ||
| originalResponseCallback; | ||
| 
     | 
||
| if (DecoratorFunctions.shouldDecorate(requestCallback.getClass())) { | ||
| requestCallback = new DecoratorFunctions.OnRequestErrorDecorator(requestCallback); | ||
| } | ||
| if (DecoratorFunctions.shouldDecorate(responseCallback.getClass())) { | ||
| responseCallback = new DecoratorFunctions.OnResponseErrorDecorator(responseCallback); | ||
| } | ||
| return new Object[] {requestCallback, responseCallback}; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.