@@ -144,7 +144,7 @@ public AsyncAdviceScope(
144144 public static AsyncAdviceScope start (HttpRequest request ) {
145145 CallDepth callDepth = CallDepth .forClass (HttpClient .class );
146146 if (callDepth .getAndIncrement () > 0 ) {
147- return new AsyncAdviceScope (null , null , null , null , callDepth );
147+ return new AsyncAdviceScope (null , null , null , request , callDepth );
148148 }
149149 Context parentContext = currentContext ();
150150 if (!instrumenter ().shouldStart (parentContext , request )) {
@@ -155,27 +155,25 @@ public static AsyncAdviceScope start(HttpRequest request) {
155155 parentContext , context , context .makeCurrent (), request , callDepth );
156156 }
157157
158- public boolean end (@ Nullable Throwable throwable ) {
159- if (callDepth .decrementAndGet () > 0 ) {
158+ public CompletableFuture <HttpResponse <?>> end (@ Nullable Throwable throwable ,
159+ @ Nullable CompletableFuture <HttpResponse <?>> future ) {
160+ if (callDepth .decrementAndGet () > 0 || scope == null ) {
160161 // async end nested call
161- return false ;
162+ return future ;
162163 }
163164 scope .close ();
164165 if (throwable != null ) {
165166 // async end with exception: ending span and no wrapping needed
166167 instrumenter ().end (context , request , null , throwable );
167- return false ;
168+ return future ;
168169 }
169- return true ;
170- }
171-
172- public CompletableFuture <HttpResponse <?>> wrapFuture (
173- CompletableFuture <HttpResponse <?>> future ) {
174170 future = future .whenComplete (new ResponseConsumer (instrumenter (), context , request ));
175171 return CompletableFutureWrapper .wrap (future , parentContext );
176172 }
173+
177174 }
178175
176+ @ Nullable
179177 @ Advice .OnMethodEnter (suppress = Throwable .class )
180178 public static AsyncAdviceScope methodEnter (
181179 @ Advice .Argument (value = 0 ) HttpRequest httpRequest ) {
@@ -185,16 +183,11 @@ public static AsyncAdviceScope methodEnter(
185183 @ AssignReturned .ToReturned
186184 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
187185 public static CompletableFuture <HttpResponse <?>> methodExit (
188- @ Advice .Return CompletableFuture <HttpResponse <?>> future ,
186+ @ Advice .Return @ Nullable CompletableFuture <HttpResponse <?>> future ,
189187 @ Advice .Thrown @ Nullable Throwable throwable ,
190188 @ Advice .Enter @ Nullable AsyncAdviceScope scope ) {
191- if (scope == null ) {
192- return future ;
193- }
194- if (scope .end (throwable )) {
195- return scope .wrapFuture (future );
196- }
197- return future ;
189+
190+ return scope == null ? future : scope .end (throwable , future );
198191 }
199192 }
200193}
0 commit comments