1

how do I get the MDC information to show up in Azure Insights. Currently I only see it in the trace log.

I am using:

  1. Quarkus 1.13.0.Final
  2. Application Insights 3.0

I have inserted the Application Insights according to these instructions => Java codeless application monitoring Azure Monitor Application Insights

Source Code

...
import org.slf4j.MDC;


@Provider
@ApplicationScoped
public class DemoRequestFilter implements ContainerRequestFilter {

    private static final String DEMO_TAG = "demoTag";

    @Override
    public void filter(final ContainerRequestContext context) {
        MDC.put(DEMO_TAG, "myDemoTag");
  
    }

}

application.yaml

log:
    console:
      format: "%d{HH:mm:ss} %-5p [%c{2.}] (%t) requestDemoTag=[%X{demoTag}]  %s%e%n"

Thanks for your help

matt-rock
  • 133
  • 2
  • 14
  • Hello! I wanted to reach out and see if you ever found a solution for this. Manually adding a JAR file and modifying the JRE settings seems a little sketchy to me. Hoping that someone had found a simpler way to export logs to Azure Monitor from a Quarkus app. – TheFunk Feb 04 '23 at 01:29

1 Answers1

0

Did you mean that you can only see MDC information in this place? And what's your target?

enter image description here

=============================UPDATE==============================

I'll share my configuration on the project. If we need to add appinsights java agent to our program, we could follow this tutorial.

First, download the jar file mentioned in the tutorial you can save it in your workspace, I stored it in the path:D:/applicationinsights-agent-3.0.2.jar

Then I created a file 'applicationinsights.json' in the same folder as jar file. In the json file, I set the connection string of the azure application insights instance. Creating a new application insights then I can get the connection string in the overview page.

Next, I need to set the jvm args. I used sts as the ide, so Menu bar-> Window-> Preference-> Java-> Installed JREs-> double click the one you used-> Default vm arguments set vaule -Xmx512m -XX:+UseG1GC -javaagent:D:/applicationinsights-agent-3.0.2.jar

enter image description here enter image description here

Adding the MDC code and starting the program, then I can get the result in the top of my answer.

If you need to deploy your program into azure app service, official doc said agent appinsights hasn't supported app service, but I find another answer which proved to be ok of this feature. That says

Enable application insights for the app service and specify an app insights instance and Add this application setting; XDT_MicrosoftApplicationInsights_Java -> 1

Let's see log4j2 configuration in my side.

enter image description here enter image description here

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL">
    <Properties>
        <Property name="pattern">%d{HH:mm:ss} %-5p [%c{2.}] (%t) requestDemoTag=[%X{demoTag}]  %s%e%n</Property>
        <Property name="logPath">logs</Property>
    </Properties>
    <Appenders>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="${pattern}"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>
Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
  • I only see the MDC information in the StackTrace. Like on the left picture of your example. Unfortunately, I don't see the MDC information in Azure. Also not in the custom properties. My goal is that the MDC information is played out in the custom properties. – matt-rock Apr 13 '21 at 07:39
  • Thanks for response sir, I've updated my answer and share my configuration. If you have further questions, pls feel free to add comment. – Tiny Wang Apr 13 '21 at 08:11
  • Thanks for your help. I have implemented all the steps described. My service is also detected in Azure Application Insights. Even when I set environment variables in applicationsinsights.json this variable is shown in CustomProperties. Only the MDC information is not displayed – matt-rock Apr 13 '21 at 09:36
  • I've added my configurations on log4j2, maybe you can compare it with yours and get some finding. – Tiny Wang Apr 13 '21 at 09:42
  • Thank you for the log4j2 settings. With the SpringBoot project, the MDC is also displayed in Azure Application Insights. However, not for the Quarkus project. So I think it is a problem between Quarkus, sl4j and Azure Application Insights. Somewhere the MDC information gets lost – matt-rock Apr 13 '21 at 10:07
  • I'm sorry for it and I really know little about Quarkus, I'm afraid there's bug exist. Maybe you can try to use java sdk sir. – Tiny Wang Apr 13 '21 at 14:47
  • No problem. But thanks for your help. When I have a solution, I will post this here – matt-rock Apr 14 '21 at 07:09