我正在使用 Java 在 Cloud Run 上构建微服务。所以,我想为这些服务使用 CloudTrace。但它并没有像我预期的那样工作。ADeadlineExceededException
被提升。
我可以在本地 PC 上运行相同的服务。而在那个时候,它是没有问题的。我可以在 CloudTrace 上确认跟踪。但是当我将它们部署在 Cloud Run 上时,Tracing 不起作用……你知道吗?
代码如下。我使用 OpenCensus 库。
var spanContext = TEXT_FORMAT.extract(request, GETTER);
var builder = Tracing.getTracer()
.spanBuilderWithRemoteParent(name, spanContext);
builder.setRecordEvents(true)
.setSampler(Samplers.alwaysSample())
.startScopedSpan();
try ( var ss = builder.setRecordEvents(true)
.setSampler(Samplers.alwaysSample())
.startScopedSpan()) {
var span = Tracing.getTracer().getCurrentSpan();
span.putAttribute(HttpTraceAttributeConstants.HTTP_HOST, AttributeValue.stringAttributeValue(host));
span.putAttribute(HttpTraceAttributeConstants.HTTP_METHOD, AttributeValue.stringAttributeValue(method));
span.putAttribute(HttpTraceAttributeConstants.HTTP_PATH, AttributeValue.stringAttributeValue(path));
// Something logic
}
错误如下。
2020-08-31 15:28:23.065 PDT2020-08-31 22:28:22,462 WARNING [io.ope.tra.exp.ExportComponent] (ExportComponent.ServiceExporterThread-0) Exception thrown by the service export io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter: com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: ClientCall started after deadline exceeded: -2.199245981s from now
2020-08-31 15:28:23.065 PDT at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:51)
2020-08-31 15:28:23.065 PDT at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
2020-08-31 15:28:23.065 PDT at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
2020-08-31 15:28:23.065 PDT at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
2020-08-31 15:28:23.065 PDT at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1056)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1138)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:707)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.ForwardingListenableFuture.addListener(ForwardingListenableFuture.java:45)
2020-08-31 15:28:23.065 PDT at com.google.api.core.ApiFutureToListenableFuture.addListener(ApiFutureToListenableFuture.java:52)
2020-08-31 15:28:23.065 PDT at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1037)
2020-08-31 15:28:23.065 PDT at com.google.api.core.ApiFutures.addCallback(ApiFutures.java:63)
2020-08-31 15:28:23.065 PDT at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:67)
我尝试了可扩展服务代理。有用。但我想将跟踪作为应用程序的一部分。