Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ public static ClientContext create(StubSettings settings) throws IOException {
ApiTracerContext.newBuilder()
.setServerAddress(endpointContext.resolvedServerAddress())
.build();
ApiTracerFactory apiTracerFactory = settings.getTracerFactory().withContext(apiTracerContext);
ApiTracerFactory apiTracerFactory = settings.getTracerFactory();
if (apiTracerFactory != null) {
Comment thread
diegomarquezp marked this conversation as resolved.
Outdated
apiTracerFactory = apiTracerFactory.withContext(apiTracerContext);
}
if (apiTracerFactory == null) {
apiTracerFactory = BaseApiTracerFactory.getInstance();
}
Comment thread
diegomarquezp marked this conversation as resolved.
Outdated

return newBuilder()
.setBackgroundResources(backgroundResources.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import com.google.api.gax.rpc.testing.FakeClientSettings;
import com.google.api.gax.rpc.testing.FakeStubSettings;
import com.google.api.gax.rpc.testing.FakeTransportChannel;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.auth.ApiKeyCredentials;
import com.google.auth.CredentialTypeForMetrics;
import com.google.auth.Credentials;
Expand Down Expand Up @@ -1287,4 +1289,35 @@ void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException {
// is not passed to the TransportChannelProvider
ClientContext.create(clientSettings);
}

@Test
void testCreate_withNullTracerFactory() throws IOException {
FakeStubSettings.Builder builder = FakeStubSettings.newBuilder();
builder.setTransportChannelProvider(getFakeTransportChannelProvider());
builder.setCredentialsProvider(
FixedCredentialsProvider.create(Mockito.mock(Credentials.class)));

FakeStubSettings settings = Mockito.spy(builder.build());
Mockito.doReturn(null).when(settings).getTracerFactory();

ClientContext context = ClientContext.create(settings);
assertThat(context.getTracerFactory()).isSameInstanceAs(BaseApiTracerFactory.getInstance());
}

@Test
void testCreate_withTracerFactoryReturningNullWithContext() throws IOException {
FakeStubSettings.Builder builder = FakeStubSettings.newBuilder();
builder.setTransportChannelProvider(getFakeTransportChannelProvider());
builder.setCredentialsProvider(
FixedCredentialsProvider.create(Mockito.mock(Credentials.class)));

ApiTracerFactory apiTracerFactory = Mockito.mock(ApiTracerFactory.class);
Mockito.doReturn(null).when(apiTracerFactory).withContext(Mockito.any());

FakeStubSettings settings = Mockito.spy(builder.build());
Mockito.doReturn(apiTracerFactory).when(settings).getTracerFactory();

ClientContext context = ClientContext.create(settings);
assertThat(context.getTracerFactory()).isSameInstanceAs(BaseApiTracerFactory.getInstance());
}
}
Loading