【问题标题】:Stackdriver log entries with same trace ID not associated具有相同跟踪 ID 的 Stackdriver 日志条目未关联
【发布时间】:2020-04-09 13:22:31
【问题描述】:

我在 GKE 上托管了一个 NodeJS 项目,并启用了 trace agent 和 Stackdriver 日志记录。该项目正在使用winston 登录到stdout,如下所示:

const { createLogger, format, transports } = require('winston');
const { combine, json } = format;

const addTraceId = format(info => {
  const agent = global._google_trace_agent;
  if (agent) {
    const traceProjectId = agent.getWriterProjectId();
    const traceId = agent.getCurrentContextId();
    if (traceProjectId && traceId) {
      info['logging.googleapis.com/trace'] = `projects/${traceProjectId}/traces/${traceId}`;
    }
  }
});

createLogger({
  level: 'debug',
  transports: new transports.Console()
  format: combine(
    addTraceId(),
    json()
  );
});

我可以看到 traceId 出现在 Stackdriver 中,并且在同一跟踪中的日志中保持一致。但它们都是单独的日志条目,而不是折叠在第一个条目下。

我检查了请求日志也有标题x-cloud-trace-context: "a54d7110fc59c879b7ae67fb481fb89b/113593995793831;o=1"

另外,我可以在跟踪列表控制台中看到正确完成的跟踪。 当我将其部署到 GAE 时,我可以看到关联的日志并在第一个条目下折叠。有什么想法吗?

【问题讨论】:

  • 您可能想看看this,似乎已经有报告表明您正在处理与该线程中的解决方案相同的行为
  • 谢谢。我没有使用@google-cloud/logging-winston。仅仅添加 traceId 和 http 请求格式并不值得(除非我错过了什么。)而是手动进行的。我的问题是 traceIds 已附加但 Stackdriver UI 没有折叠它们。
  • 您分享的两个条目具有不同的严重性,这可能与它们没有被组合在一起的原因有关。我知道这不会在 App Engine 中发生,您能否分享那里的日志条目?

标签: google-cloud-platform stackdriver winston google-cloud-stackdriver


【解决方案1】:

使用logName app 而不是stdout

【讨论】:

    猜你喜欢
    • 2020-02-13
    • 2019-08-08
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多