Consuming data from Google Stackdriver errorreporting with the java client on GAE

Problem:

We have a Java application running on Google App Engine that needs to process errors gathered on Google Stackdriver.

We wrote some code using the Stackdriver Error Reporting API Java Client Library obtained as the following maven dependency

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-errorreporting</artifactId>
    <version>0.9.3-alpha</version>
</dependency>

but it seems not compatible with GAE, as it complains for

Caused by: java.lang.SecurityException: Google App Engine does not support Runtime.addShutdownHook
  at com.google.appengine.runtime.Request.process-d6bb19ff7906421f(Request.java)
  at java.lang.Runtime.addShutdownHook(Runtime.java:45)
  at com.google.common.util.concurrent.MoreExecutors$Application.addShutdownHook(MoreExecutors.java:223)
  at com.google.common.util.concurrent.MoreExecutors$Application.addDelayedShutdownHook(MoreExecutors.java:195)
  at com.google.common.util.concurrent.MoreExecutors$Application.getExitingScheduledExecutorService(MoreExecutors.java:187)
  at com.google.common.util.concurrent.MoreExecutors$Application.getExitingScheduledExecutorService(MoreExecutors.java:219)
  at com.google.common.util.concurrent.MoreExecutors.getExitingScheduledExecutorService(MoreExecutors.java:169)
  at com.google.api.gax.grpc.InstantiatingExecutorProvider.getExecutor(InstantiatingExecutorProvider.java:51)
  at com.google.api.gax.grpc.ChannelAndExecutor.create(ChannelAndExecutor.java:62)
  at com.google.api.gax.grpc.ClientSettings.getChannelAndExecutor(ClientSettings.java:81)
  at com.google.cloud.errorreporting.spi.v1beta1.ErrorStatsServiceClient.<init>(ErrorStatsServiceClient.java:133)
  at com.google.cloud.errorreporting.spi.v1beta1.ErrorStatsServiceClient.create(ErrorStatsServiceClient.java:123)
  at com.google.cloud.errorreporting.spi.v1beta1.ErrorStatsServiceClient.create(ErrorStatsServiceClient.java:114)
  at com.acme.gcp.errors.App.processErrorStats(App.java:39)

So the question is: is there any way for consuming Google Stackdriver errors from GAE, other than fetching data from the REST api through the Google HTTP Client?

UPDATE

The error arises irrespective of the serviceClient configurations tried so far.

i.e. this is one of the configuration attempts leading to the error:

ErrorStatsServiceSettings errorStatsServiceSettings = ErrorStatsServiceSettings
    .defaultBuilder()
    .deleteEventsSettings()
    .getRetrySettingsBuilder()
    .setTotalTimeout(Duration.standardSeconds(30))
    .build();
ErrorStatsServiceClient.create(errorStatsServiceSettings); //error arising here

UPDATE2

There is an issue for Java gRPC GAE compatibility at github.com/GoogleCloudPlatform/google-cloud-java/issues/1490#issuecomment-283597294



Solution:

We ended up using another library from Google providing a Java API for Stack driver error reporting:

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-clouderrorreporting</artifactId>
    <version>v1beta1-rev260-1.22.0</version>
</dependency>

It must be properly configured with auth credentials.
In fact it actually issues HTTP calls to the REST services (no gRPC) as would be done outside GAE.

Read more here: Source link