【问题标题】:How to post process JSON logs with Datadog?如何使用 Datadog 发布处理 JSON 日志?
【发布时间】:2020-05-26 23:08:34
【问题描述】:

我们的应用程序以 JSON 格式登录。根据 Datadog 的文档,管道不处理 JSON 日志。如何使用基于同一日志行的不同值的附加字段来丰富 JSON 日志?

我有这行:

{"requestUri":"/customers/2934ht8/users"}

我想要这条线:

{"requestUri":"/customers/2934ht8/users","customerId":"2934ht8"}

Datadog 可以做到这一点吗?我不想将我们的记录器更改为customerId 到日志输出。

【问题讨论】:

    标签: datadog


    【解决方案1】:

    是的,这是可能的。您可以使用 grok 解析器在 processing pipeline 中执行此操作,但您需要在高级设置 (docs here) 中配置 grok 解析器应用于哪个属性。 (默认情况下 grok 解析器适用于“消息”属性,但您可以将它们配置为解析任何属性。)

    在这种情况下,您需要将 Extract From 字段设置为 requestUriHelper Rules 部分不是必需的。然后在主要的Define Parsing Rules 部分中,您将插入类似于以下的规则:

    parse_customer_id \/customers\/%{notSpace:customerId}\/users
    

    甚至更远

    parse_customer_id \/%{notSpace}\/%{notSpace:customerId}\/%{notSpace}
    

    【讨论】:

    • 我这样做了。但它不起作用,因为自定义管道不处理 JSON 日志:Datadog automatically parses JSON-formatted logs. When your logs are not JSON-formatted, Datadog enables you to add value to your raw logs by sending them through a processing pipeline.docs.datadoghq.com/logs/processing/pipelines/#pipelines-goal
    • 我相信即使在自动解析的 JSON 应用后它仍然可以工作——你确定日志被路由到正确的管道吗?也许值得联系 Datadog 支持以进行快速审查。
    • 我也没有看到这适用于已经以 JSON 形式出现的日志。但是他们发布的一个例子表明它应该:datadoghq.com/blog/how-to-categorize-logs/…
    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多