Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -55,6 +55,7 @@
import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.RetryHelper;
import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.ServiceOptions;
import com.google.cloud.grpc.GcpManagedChannelBuilder;
import com.google.cloud.grpc.GcpManagedChannelOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpMetricsOptions;
Expand Down Expand Up @@ -296,7 +297,8 @@ public GapicSpannerRpc(final SpannerOptions options) {
ApiClientHeaderProvider internalHeaderProvider =
internalHeaderProviderBuilder
.setClientLibToken(
options.getClientLibToken(), GaxProperties.getLibraryVersion(options.getClass()))
options.getClientLibToken() + " " + ServiceOptions.getGoogApiClientLibName(),
GaxProperties.getLibraryVersion(options.getClass()))
.setTransportToken(
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.api.gax.rpc.HeaderProvider;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.OAuth2Credentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Dialect;
Expand Down Expand Up @@ -77,6 +78,7 @@
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -181,6 +183,12 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
String auth =
headers.get(Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER));
assertThat(auth).isEqualTo("Bearer " + VARIABLE_OAUTH_TOKEN);
String clientLibToken =
headers.get(
Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER));
assertNotNull(clientLibToken);
assertTrue(
clientLibToken.contains(ServiceOptions.getGoogApiClientLibName() + "/"));
if (call.getMethodDescriptor()
.equals(SpannerGrpc.getExecuteStreamingSqlMethod())
|| call.getMethodDescriptor().equals(SpannerGrpc.getExecuteSqlMethod())) {
Expand Down Expand Up @@ -575,6 +583,27 @@ public void testRouteToLeaderHeaderWithLeaderAwareRoutingDisabled() {
assertFalse(isRouteToLeader);
}

@Test
public void testCustomClientLibToken_alsoContainsDefaultToken() {
SpannerOptions options =
createSpannerOptions().toBuilder().setClientLibToken("pg-adapter").build();
try (Spanner spanner = options.getService()) {
DatabaseClient databaseClient =
spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"));
TransactionRunner runner = databaseClient.readWriteTransaction();
runner.run(transaction -> transaction.executeUpdate(UPDATE_FOO_STATEMENT));
}
Key<String> key = Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER);
assertTrue(lastSeenHeaders.containsKey(key));
assertTrue(
lastSeenHeaders.get(key),
Objects.requireNonNull(lastSeenHeaders.get(key)).contains("pg-adapter"));
assertTrue(
lastSeenHeaders.get(key),
Objects.requireNonNull(lastSeenHeaders.get(key))
.contains(ServiceOptions.getGoogApiClientLibName() + "/"));
}

private SpannerOptions createSpannerOptions() {
String endpoint = address.getHostString() + ":" + server.getPort();
return SpannerOptions.newBuilder()
Expand Down