|
35 | 35 | import com.google.api.gax.rpc.ApiCallContext;
|
36 | 36 | import com.google.api.gax.rpc.ApiClientHeaderProvider;
|
37 | 37 | import com.google.api.gax.rpc.ApiException;
|
| 38 | +import com.google.api.gax.rpc.FixedHeaderProvider; |
38 | 39 | import com.google.api.gax.rpc.HeaderProvider;
|
39 | 40 | import com.google.api.gax.rpc.InstantiatingWatchdogProvider;
|
40 | 41 | import com.google.api.gax.rpc.OperationCallable;
|
|
70 | 71 | import com.google.common.base.MoreObjects;
|
71 | 72 | import com.google.common.base.Preconditions;
|
72 | 73 | import com.google.common.collect.ImmutableList;
|
| 74 | +import com.google.common.collect.ImmutableMap; |
73 | 75 | import com.google.common.util.concurrent.RateLimiter;
|
74 | 76 | import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
75 | 77 | import com.google.iam.v1.GetIamPolicyRequest;
|
@@ -232,6 +234,8 @@ private void awaitTermination() throws InterruptedException {
|
232 | 234 | private static final int DEFAULT_TIMEOUT_SECONDS = 30 * 60;
|
233 | 235 | private static final int DEFAULT_PERIOD_SECONDS = 10;
|
234 | 236 | private static final int GRPC_KEEPALIVE_SECONDS = 2 * 60;
|
| 237 | +private static final String USER_AGENT_KEY = "user-agent"; |
| 238 | +private static final String CLIENT_LIBRARY_LANGUAGE = "spanner-java"; |
235 | 239 |
|
236 | 240 | // TODO(weiranf): Remove this temporary endpoint once DirectPath goes to public beta.
|
237 | 241 | private static final String DIRECT_PATH_ENDPOINT = "aa423245250f2bbf.sandbox.googleapis.com:443";
|
@@ -297,9 +301,20 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
297 | 301 | .build();
|
298 | 302 |
|
299 | 303 | HeaderProvider mergedHeaderProvider = options.getMergedHeaderProvider(internalHeaderProvider);
|
| 304 | +Map<String, String> headersWithUserAgent = |
| 305 | +ImmutableMap.<String, String>builder() |
| 306 | +.put( |
| 307 | +USER_AGENT_KEY, |
| 308 | +CLIENT_LIBRARY_LANGUAGE |
| 309 | ++ "/" |
| 310 | ++ GaxProperties.getLibraryVersion(GapicSpannerRpc.class)) |
| 311 | +.putAll(mergedHeaderProvider.getHeaders()) |
| 312 | +.build(); |
| 313 | +final HeaderProvider headerProviderWithUserAgent = |
| 314 | +FixedHeaderProvider.create(headersWithUserAgent); |
300 | 315 | this.metadataProvider =
|
301 | 316 | SpannerMetadataProvider.create(
|
302 |
| -mergedHeaderProvider.getHeaders(), |
| 317 | +headerProviderWithUserAgent.getHeaders(), |
303 | 318 | internalHeaderProviderBuilder.getResourceHeaderKey());
|
304 | 319 | this.callCredentialsProvider = options.getCallCredentialsProvider();
|
305 | 320 | this.compressorName = options.getCompressorName();
|
@@ -338,7 +353,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
338 | 353 | options.getInterceptorProvider(),
|
339 | 354 | SpannerInterceptorProvider.createDefault()))
|
340 | 355 | .withEncoding(compressorName))
|
341 |
| -.setHeaderProvider(mergedHeaderProvider); |
| 356 | +.setHeaderProvider(headerProviderWithUserAgent); |
342 | 357 |
|
343 | 358 | // TODO(weiranf): Set to true by default once DirectPath goes to public beta.
|
344 | 359 | if (shouldAttemptDirectPath()) {
|
@@ -478,8 +493,10 @@ private static void checkEmulatorConnection(
|
478 | 493 | throw SpannerExceptionFactory.newSpannerException(
|
479 | 494 | ErrorCode.UNAVAILABLE,
|
480 | 495 | String.format(
|
481 |
| -"The environment variable SPANNER_EMULATOR_HOST has been set to %s, but no running emulator could be found at that address.\n" |
482 |
| -+ "Did you forget to start the emulator, or to unset the environment variable?", |
| 496 | +"The environment variable SPANNER_EMULATOR_HOST has been set to %s, but no running" |
| 497 | ++ " emulator could be found at that address.\n" |
| 498 | ++ "Did you forget to start the emulator, or to unset the environment" |
| 499 | ++ " variable?", |
483 | 500 | emulatorHost));
|
484 | 501 | }
|
485 | 502 | }
|
|
0 commit comments