简体   繁体   English

Quarkus - MDC - Azure Application Insights

[英]Quarkus - MDC - Azure Application Insights

I'm having trouble with configuring MDC for Quarkus and to expose the additional information to Azure Application Insight.我在为 Quarkus 配置 MDC 并将附加信息公开给 Azure Application Insight 时遇到问题。 When I run the application locally, than the information is shown correctly in my console.当我在本地运行应用程序时,信息会正确显示在我的控制台中。

Quarkus version: 2.11.2.Final Quarkus 版本:2.11.2.Final

application.yml:应用程序.yml:

quarkus:
    log:
        console:
            format: "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) [%X] %s%e%n"

code example:代码示例:

import org.jboss.logging.Logger;

@Inject
Logger log;

@GET
@Path("/hello")
public String sayHello() {
    MDC.put("example", "abc");
    log.info("Say hello...");
    return "Hello";
}

The value 'Say hello' is shown in the Azure Application Insights but the value 'abc' not. Azure Application Insights 中显示了值“Say hello”,但值“abc”没有。

Any ideas?有任何想法吗?

All your code is ok but you are missing something here.您的所有代码都可以,但是您在这里遗漏了一些东西。

According to documentation format spec , you have to specify which MDC property you want to log by adding its name.根据文档格式规范,您必须通过添加名称来指定要记录的 MDC 属性。

In your case it would be 'example', see updated application.yml :在您的情况下,它将是“示例”,请参阅更新的application.yml

quarkus:
    log:
        console:
            format: "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) [%X{example}] %s%e%n"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM