1
votes

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 https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1490#issuecomment-283597294

2
According to this document cloud.google.com/error-reporting/docs you can use Stackdriver error reporting on both Google app engine standard environment and flexible environment.Bravin Balasubramaniam
@BravinBalasubramaniam in fact I'd say it should work... maybe it is simply a matter of setting proper executors (for GAE compatibility).Davide Cavestro

2 Answers

0
votes

Java gRPC clients do not yet work in the App Engine Standard Environment. This should be fixed eventually, of course.

In the meantime, you could fall back to using the REST-based API, or, in case you are not bound to using Java, implement a small Go-based app (in the same cloud project) which fetches the error reports, stores them away or maybe passes them on to your Java app via Task Queues.

0
votes

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.