我们有一个在 Google App Engine 上运行的 Java 应用程序,它需要处理在 Google Stackdriver 上收集的错误。
我们使用 Stackdriver Error Reporting API Java Client Library编写了一些代码,作为以下 maven 依赖项获得
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-errorreporting</artifactId>
<version>0.9.3-alpha</version>
</dependency>
但它似乎与 GAE 不兼容,因为它抱怨
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)
所以问题是:除了通过 Google HTTP 客户端从 REST api 获取数据之外,还有什么方法可以从 GAE 中使用 Google Stackdriver 错误?
更新
无论到目前为止尝试的serviceClient配置如何,都会出现错误。
即这是导致错误的配置尝试之一:
ErrorStatsServiceSettings errorStatsServiceSettings = ErrorStatsServiceSettings
.defaultBuilder()
.deleteEventsSettings()
.getRetrySettingsBuilder()
.setTotalTimeout(Duration.standardSeconds(30))
.build();
ErrorStatsServiceClient.create(errorStatsServiceSettings); //error arising here
更新2