Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何在GCP Stackdriver日志UI中嵌套日志条目?_Google Cloud Platform_Stackdriver_Google Cloud Logging - Fatal编程技术网

Google cloud platform 如何在GCP Stackdriver日志UI中嵌套日志条目?

Google cloud platform 如何在GCP Stackdriver日志UI中嵌套日志条目?,google-cloud-platform,stackdriver,google-cloud-logging,Google Cloud Platform,Stackdriver,Google Cloud Logging,使用GCP日志客户端或API术语,如何嵌套如图所示的日志条目 本用例在中进行了解释 确保在您发送的请求和应用程序日志中将traceId字段设置为非空值。下面是Scala中的示例代码: import com.google.cloud.MonitoredResource import com.google.cloud.logging.Payload._ import com.google.cloud.logging._ import collection.JavaConverters._ impor

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


本用例在中进行了解释

确保在您发送的请求和应用程序日志中将
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)
最后,日志条目应显示在各自的日志中,并作为请求的子项显示在“交叉日志”中,如下所示: