使用GCP日志客户端或API术语,如何嵌套此图中所示的日志条目?

发布于 2018-02-28 08:06:58
此用例在AppEngline Logs docs中进行了说明。
还要确保将您发送的请求和应用程序日志上的traceId字段设置为非空值。以下是Scala中的示例代码:
import com.google.cloud.MonitoredResource
import com.google.cloud.logging.Payload._
import com.google.cloud.logging._
import collection.JavaConverters._
import org.threeten.bp.Duration
val logging = LoggingOptions.getDefaultInstance().getService()
val traceId = "keasdfwxcbrbntpoiuwehrtiojsadf";
var firstEntry = {
LogEntry.newBuilder(StringPayload.of("string-payload-one"))
.setSeverity(Severity.ERROR)
.setLogName("app")
.setTimestamp(1519955138399L)
.setResource(MonitoredResource.newBuilder("global").build())
.setLabels(Map("environment" -> "testing").asJava)
.setTrace(traceId)
.build()
}
var midEntry = {
LogEntry.newBuilder(StringPayload.of("string-payload-two"))
.setSeverity(Severity.INFO)
.setLogName("request")
.setResource(MonitoredResource.newBuilder("global").build())
.setHttpRequest(HttpRequest.newBuilder().setStatus(200).setRequestUrl("/about-us").setLatency(Duration.ofMillis(1234)).build())
.setTimestamp(1519955137906L)
.setLabels(Map("environment" -> "testing").asJava)
.setTrace(traceId)
.build()
}
var lastEntry = {
LogEntry.newBuilder(StringPayload.of("string-payload-three"))
.setSeverity(Severity.ERROR)
.setLogName("app")
.setResource(MonitoredResource.newBuilder("global").build())
.setTimestamp(1519955138523L)
.setLabels(Map("environment" -> "testing").asJava)
.setTrace(traceId)
.build()
}
logging.write(List(firstEntry, midEntry, lastEntry).asJava)最后,日志条目应该显示在它们各自的日志和“交叉日志”中,作为它们的请求的子项,如下所示:

https://stackoverflow.com/questions/49000968
复制相似问题