如何在从 Spring 启动时使用 logback 无代理发送日志时为 datadog 定义源标记?

How to define source-tag for datadog when sending logs agentless with logback from Spring Boot?

如何配置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 标签。从我的服务发送的日志消息在 datadog 中显示有两个标签:source:javasource:undefined:

如何删除 source:undefined 标签,以便 datadog 正确识别来源?

试试这个

<encoder class="net.logstash.logback.encoder.LogstashEncoder">
        <customFields>
            {"service":"ServiceName","ddsource":"java"}
        </customFields>...
</encoder>