【问题标题】:How to Viewing trace logs from OpenTelemetry in Elastic APM如何在 Elastic APM 中查看来自 OpenTelemetry 的跟踪日志
【发布时间】:2021-06-26 07:30:00
【问题描述】:

我从 Elastic APM 中的 opentelemetry-collector 接收日志 日志结构:

"{Timestamp:HH:mm:ss} {Level:u3} trace.id={TraceId} transaction.id={SpanId}{NewLine}{Message:lj}{NewLine}{Exception}"

示例:

08:27:47 INF trace.id=898a7716358b25408d4f193f1cd17831 transaction.id=4f7590e4ba80b64b SOME MSG

我尝试使用管道

POST _ingest/pipeline/_simulate {   "pipeline": {   "description" : "parse multiple patterns",   "processors": [
    {
      "grok": {
        "field": "message",
        "patterns": ["%{TIMESTAMP_ISO8601:logtime} %{LOGLEVEL:loglevel} \\[trace.id=%{TRACE_ID:trace.id}(?: transaction.id=%{SPAN_ID:transaction.id})?\\] %{GREEDYDATA:message}"],
        "pattern_definitions": {
          "TRACE_ID": "[0-9A-Fa-f]{32}",
          "SPAN_ID": "[0-9A-Fa-f]{16}"
        }
      },
      "date": { "field": "logtime", "target_field": "@timestamp", "formats": ["HH:mm:ss"] }
    }   ] } }

我的目标是查看 Elastic APM 中的日志

 {
        "@timestamp": 2021-01-05T10:10:10",
    
        "message":  "Protocol Port MIs-Match",
        "trace": {
            "traceId": "898a7716358b25408d4f193f1cd17831",
            "spanId": "4f7590e4ba80b64b"
        }
    }

【问题讨论】:

  • 当你点击“时间轴|元数据”右侧的“日志”时,你看到了什么?
  • 它是空的,因为我没有收到格式正确的日志
  • 那您需要说明您目前如何将日志发送到 Elastic?
  • 我从 opentelemetry-collector 发送日志。据我了解,我需要将我的日志解析为以下结构: { "@timestamp": 2021-01-05T10:10:10", "message": "Protocol Port MIs-Match", "trace": { "traceId" :“898a7716358b25408d4f193f1cd17831”,“spanId”:“4f7590e4ba80b64b”}}

标签: elasticsearch logging kibana trace open-telemetry


【解决方案1】:

到目前为止做得很好。您的管道几乎很好,但是,grok 模式需要一些修复,并且您有一些孤儿花括号。这是一个工作示例:

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "description": "parse multiple patterns",
    "processors": [
      {
        "grok": {
          "field": "message",
          "patterns": [
            """%{TIME:logtime} %{WORD:loglevel} trace.id=%{TRACE_ID:trace.id}(?: transaction.id=%{SPAN_ID:transaction.id})? %{GREEDYDATA:message}"""
          ],
          "pattern_definitions": {
            "TRACE_ID": "[0-9A-Fa-f]{32}",
            "SPAN_ID": "[0-9A-Fa-f]{16}"
          }
        }
      },
      {
        "date": {
          "field": "logtime",
          "target_field": "@timestamp",
          "formats": [
            "HH:mm:ss"
          ]
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "message": "08:27:47 INF trace.id=898a7716358b25408d4f193f1cd17831 transaction.id=4f7590e4ba80b64b SOME MSG"
      }
    }
  ]
}

回复:

{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "trace" : {
            "id" : "898a7716358b25408d4f193f1cd17831"
          },
          "@timestamp" : "2021-01-01T08:27:47.000Z",
          "loglevel" : "INF",
          "message" : "SOME MSG",
          "logtime" : "08:27:47",
          "transaction" : {
            "id" : "4f7590e4ba80b64b"
          }
        },
        "_ingest" : {
          "timestamp" : "2021-03-30T11:07:52.067275598Z"
        }
      }
    }
  ]
}

请注意,缺少确切日期,因此@timestamp 字段解析为今年 1 月 1 日。

【讨论】:

  • 也许你知道为什么当我添加所有时间戳都为 Jan 1, 2021 @ 14:55:02.000 的日志时
  • 问题是消息只有时间分量:08:27:47,没有日期
猜你喜欢
  • 2023-01-18
  • 1970-01-01
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 2011-04-01
  • 2022-08-17
  • 2022-09-29
相关资源
最近更新 更多