Skip to content

Commit

Permalink
feat: include User agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanli-ml committed Dec 15, 2020
1 parent 9851996 commit 6a41e9a
Showing 1 changed file with 19 additions and 3 deletions.
Expand Up @@ -152,6 +152,7 @@
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -338,7 +339,20 @@ public GapicSpannerRpc(final SpannerOptions options) {
options.getInterceptorProvider(),
SpannerInterceptorProvider.createDefault()))
.withEncoding(compressorName))
.setHeaderProvider(mergedHeaderProvider);
.setHeaderProvider(mergedHeaderProvider)

// Inject client library version to `user-agent`
.setHeaderProvider(
new HeaderProvider() {
@Override
public Map<String, String> getHeaders() {
final HashMap<String, String> headers = new HashMap<>();
headers.put(
"user-agent",
"spanner-java/" + GaxProperties.getLibraryVersion(GapicSpannerRpc.class));
return headers;
}
});

// TODO(weiranf): Set to true by default once DirectPath goes to public beta.
if (shouldAttemptDirectPath()) {
Expand Down Expand Up @@ -478,8 +492,10 @@ private static void checkEmulatorConnection(
throw SpannerExceptionFactory.newSpannerException(
ErrorCode.UNAVAILABLE,
String.format(
"The environment variable SPANNER_EMULATOR_HOST has been set to %s, but no running emulator could be found at that address.\n"
+ "Did you forget to start the emulator, or to unset the environment variable?",
"The environment variable SPANNER_EMULATOR_HOST has been set to %s, but no running"
+ " emulator could be found at that address.\n"
+ "Did you forget to start the emulator, or to unset the environment"
+ " variable?",
emulatorHost));
}
}
Expand Down

0 comments on commit 6a41e9a

Please sign in to comment.