3737import java .util .Collection ;
3838import java .util .Collections ;
3939import java .util .LinkedHashSet ;
40- import java .util .Objects ;
4140import java .util .concurrent .Executor ;
4241import javax .annotation .Nonnull ;
4342import javax .annotation .Nullable ;
@@ -176,7 +175,7 @@ public final ClientStream newStream(
176175 */
177176 @ GuardedBy ("lock" )
178177 private PendingStream createPendingStream (PickSubchannelArgs args , ClientStreamTracer [] tracers ,
179- PickResult pickResult , @ Nullable String delayType , @ Nullable String delayReason ) {
178+ PickResult pickResult , String delayType , String delayReason ) {
180179 PendingStream pendingStream = new PendingStream (args , tracers , delayType , delayReason );
181180 if (args .getCallOptions ().isWaitForReady () && pickResult != null && pickResult .hasResult ()) {
182181 pendingStream .lastPickStatus = pickResult .getStatus ();
@@ -388,7 +387,10 @@ private static String determineQueuingDelayReason(@Nullable PickResult pickResul
388387 return "subchannel returned by LB picker has no connected subchannel" ;
389388 }
390389 if (!pickResult .getStatus ().isOk ()) {
391- return "wait_for_ready RPC failed with status: " + pickResult .getStatus ();
390+ Status status = pickResult .getStatus ();
391+ // Status.toString() would append the cause's stack trace.
392+ return "wait_for_ready RPC failed with status: " + status .getCode ()
393+ + (status .getDescription () == null ? "" : ": " + status .getDescription ());
392394 }
393395 if (pickResult .getDelayReason () != null ) {
394396 return pickResult .getDelayReason ();
@@ -407,16 +409,14 @@ private class PendingStream extends DelayedStream {
407409 @ Nullable private String activeDelayReason ;
408410
409411 private PendingStream (PickSubchannelArgs args , ClientStreamTracer [] tracers ,
410- @ Nullable String initialType , @ Nullable String initialReason ) {
412+ String delayType , String delayReason ) {
411413 super ("connecting_and_lb" );
412414 this .args = args ;
413415 this .tracers = tracers ;
414- this .activeDelayType = initialType ;
415- this .activeDelayReason = initialReason ;
416- if (initialType != null ) {
417- for (ClientStreamTracer tracer : tracers ) {
418- tracer .recordAttemptDelayStart (initialType , initialReason != null ? initialReason : "" );
419- }
416+ this .activeDelayType = delayType ;
417+ this .activeDelayReason = delayReason ;
418+ for (ClientStreamTracer tracer : tracers ) {
419+ tracer .recordDelayStart (delayType , delayReason );
420420 }
421421 }
422422
@@ -427,30 +427,23 @@ private PendingStream(PickSubchannelArgs args, ClientStreamTracer[] tracers,
427427 * spans are ended and a new segment is initiated. If only {@code newReason} changes, a
428428 * structured transition event is appended to the active span without span re-creation.
429429 */
430- synchronized void updateDelay (@ Nullable String newType , @ Nullable String newReason ) {
430+ synchronized void updateDelay (String newType , String newReason ) {
431431 if (getRealStream () != null ) {
432432 return ;
433433 }
434- if (!Objects .equals (activeDelayType , newType )) {
434+ if (!newType .equals (activeDelayType )) {
435435 // Delay type changed (e.g., from RLS lookup to connecting). End the previous delay.
436- if (activeDelayType != null ) {
437- for (ClientStreamTracer tracer : tracers ) {
438- tracer .recordAttemptDelayEnd ();
439- }
440- }
436+ endDelay ();
441437 activeDelayType = newType ;
442- activeDelayReason = null ;
443- if (newType != null ) {
444- for (ClientStreamTracer tracer : tracers ) {
445- tracer .recordAttemptDelayStart (newType , newReason != null ? newReason : "" );
446- }
438+ activeDelayReason = newReason ;
439+ for (ClientStreamTracer tracer : tracers ) {
440+ tracer .recordDelayStart (newType , newReason );
447441 }
448- }
449- if (newType != null && newReason != null && !Objects .equals (activeDelayReason , newReason )) {
442+ } else if (!newReason .equals (activeDelayReason )) {
450443 // Delay type is unchanged, but the reason changed (e.g., priority failover).
451444 activeDelayReason = newReason ;
452445 for (ClientStreamTracer tracer : tracers ) {
453- tracer .recordAttemptDelayReasonChanged ( newReason );
446+ tracer .recordDelayReasonChanged ( newType , newReason );
454447 }
455448 }
456449 }
@@ -459,12 +452,13 @@ synchronized void updateDelay(@Nullable String newType, @Nullable String newReas
459452 * Ends active attempt delay segment telemetry upon stream creation or stream cancellation.
460453 */
461454 synchronized void endDelay () {
462- if (activeDelayType != null ) {
463- for (ClientStreamTracer tracer : tracers ) {
464- tracer .recordAttemptDelayEnd ();
465- }
455+ String delayType = activeDelayType ;
456+ if (delayType != null ) {
466457 activeDelayType = null ;
467458 activeDelayReason = null ;
459+ for (ClientStreamTracer tracer : tracers ) {
460+ tracer .recordDelayEnd (delayType );
461+ }
468462 }
469463 }
470464
0 commit comments