diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index ddd32c3d7adf..f63892affdaa 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -18,6 +18,8 @@ import static com.google.cloud.datastore.Validator.validateNamespace; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestInitializer; import com.google.cloud.HttpServiceOptions; import com.google.cloud.datastore.spi.DatastoreRpc; import com.google.cloud.datastore.spi.DatastoreRpcFactory; @@ -25,6 +27,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; +import java.io.IOException; import java.lang.reflect.Method; import java.util.Objects; import java.util.Set; @@ -90,6 +93,18 @@ private DatastoreOptions(Builder builder) { namespace = builder.namespace != null ? builder.namespace : defaultNamespace(); } + @Override + public HttpRequestInitializer httpRequestInitializer() { + final HttpRequestInitializer delegate = super.httpRequestInitializer(); + return new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest httpRequest) throws IOException { + delegate.initialize(httpRequest); + httpRequest.getHeaders().setUserAgent(applicationName()); + } + }; + } + @Override protected String defaultHost() { String host = System.getProperty(