如何在App Engine Flex中使应用程序日志嵌套在请求日志下?

时间:2018-10-15 19:21:29

标签: logging app-engine-flexible

我有一个在App Engine Classic中运行的模块,另一个在App Engine Flexible中运行。查看在App Engine Classic中运行的日志时,日志条目会嵌套在每个请求中。

但是,当查看在App Engine Flexible中运行的日志时,它们不是嵌套的。每个日志条目似乎都与请求断开连接。这使得确定哪个日志与哪个请求关联非常困难。

我试图按照Google文档中的以下说明进行操作:

In the App Engine flexible environment, app logs can be correlated with a particular request. Following are the requirements:

The "parent" log entry must include a value for httpRequest.requestUrl.
The "child" log entry must have a different log name than the parent. Typically, the child log entry is an app log entry in the app log, whereas the parent log entry is in the request log. The values for resource.type, resource.labels, and trace must be the same in the parent and its child(ren).
The child log entry's timestamp must be within the time interval covered by the parent request. It must be earlier than parent.timestamp and later than parent.timestamp - parent.httpRequest.latency.

我试图通过执行以下操作来使用LoggerEnhancer实现此目的:

public class Enhancer extends TraceLoggingEnhancer {

  @Override
  public void enhanceLogEntry(LogEntry.Builder logEntry) {
    // add additional labels
    logEntry.addLabel("appengine.googleapis.com/trace_id",getCurrentTraceId());
  }  
}

但是听起来没有希望,有人可以通过榜样或其他方式帮助我吗?

0 个答案:

没有答案