1

怎么配置logback加标签,让datadog能识别出源?

我有以下内容logback.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration>
    <springProperty scope="local" name="DATADOG_API_KEY" source="datadog.api-key" />
    <appender name="datadog" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>intake.logs.datadoghq.com:10514</destination>
        <keepAliveDuration>1 minute</keepAliveDuration>
        <includeCallerData>true</includeCallerData>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <includeCallerData>true</includeCallerData>
            <includeTags>true</includeTags>
            <customFields>{"ddtags": "source:java"}</customFields>
            <prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
                <layout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>${DATADOG_API_KEY} %mdc{weJustNeedSthEmptyHereSoTheXMLParserWillKeepAWhitespace}</pattern>
                </layout>
            </prefix>
        </encoder>
    </appender>
    <root>
        <appender-ref ref="datadog"/>
    </root>
</configuration

自定义字段ddtags应该为 datadog 设置标签的位置。

日志显示在 datadog 中,并且一切都按预期工作,尽管有source-tag。从我的服务发送的日志消息在 datadog:source:java和中显示有两个标签source:undefined

出现在 datadog 中的标签

如何摆脱source:undefined标签以便 datadog 正确识别来源?

4

1 回答 1

2

尝试这个

<encoder class="net.logstash.logback.encoder.LogstashEncoder">
        <customFields>
            {"service":"ServiceName","ddsource":"java"}
        </customFields>...
</encoder>
于 2021-01-27T13:50:52.853 回答