3737import com .google .api .gax .rpc .ResourceNameExtractor ;
3838import com .google .api .gax .rpc .UnaryCallable ;
3939import com .google .api .gax .tracing .ApiTracerFactory .OperationType ;
40+ import com .google .common .annotations .VisibleForTesting ;
4041import com .google .common .base .Strings ;
4142import com .google .common .util .concurrent .MoreExecutors ;
4243import javax .annotation .Nullable ;
@@ -96,13 +97,7 @@ public TracedUnaryCallable(
9697 public ApiFuture <ResponseT > futureCall (RequestT request , ApiCallContext context ) {
9798 ApiTracer tracer ;
9899 if (apiTracerContext != null ) {
99- ApiTracerContext finalContext = apiTracerContext ;
100- // Extract the resource name early
101- String resourceName =
102- resourceNameExtractor != null ? resourceNameExtractor .extract (request ) : null ;
103- if (!Strings .isNullOrEmpty (resourceName )) {
104- finalContext = finalContext .toBuilder ().setDestinationResourceId (resourceName ).build ();
105- }
100+ ApiTracerContext finalContext = extractResourceNameToApiTracerContext (request );
106101 tracer = tracerFactory .newTracer (context .getTracer (), finalContext );
107102 } else {
108103 tracer = tracerFactory .newTracer (context .getTracer (), spanName , OperationType .Unary );
@@ -120,4 +115,16 @@ public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context)
120115 throw e ;
121116 }
122117 }
118+
119+ @ VisibleForTesting
120+ ApiTracerContext extractResourceNameToApiTracerContext (RequestT request ) {
121+ ApiTracerContext finalContext = apiTracerContext ;
122+ // Extract the resource name early
123+ String resourceName =
124+ resourceNameExtractor != null ? resourceNameExtractor .extract (request ) : null ;
125+ if (!Strings .isNullOrEmpty (resourceName )) {
126+ finalContext = finalContext .toBuilder ().setDestinationResourceId (resourceName ).build ();
127+ }
128+ return finalContext ;
129+ }
123130}
0 commit comments