简体   繁体   中英

Conditional verbose error logging to Azure application-insights from a Java Spring boot application

I have a spring boot application with a pretty standard logback configuration. I know I can turn on/off the verbose logging by changing the logging level property to only log errors (<root level = "ERROR">) . And I have configured my app to only log errors in the application-insights azure resource that I have, so as to avoid verbose logging till it's necessary. All of this is working fine.

However, as soon as I get an error, I want to start verbose logging for a certain period of time let's say 2hrs, so as to help with the troubleshooting. And this is what I am unable to achieve. I am pretty new to Java as well as Azure resource configurations, so any idea will be really helpful.

Thank you Tiny Wang posting your comment as an answer.

Steps for Java codeless application monitoring with Azure Monitor Application Insights.

  1. Download the agent

  2. Point the JVM to the agent Add -javaagent:path/to/applicationinsights-agent-3.2.0.jar to your application's JVM args. Tips for updating your JVM args .

  3. Point the agent to your Application Insights resource Point the agent to your Application Insights resource, either by setting an environment variable:

    APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey= ...

Or by creating a configuration file named applicationinsights.json , and placing it in the same directory as applicationinsights-agent-3.2.0.jar , with the following content:

JSON
{
  "connectionString": "InstrumentationKey=..."
}

You can find your connection string in your Application Insights resource.

Start up your application and go to your Application Insights resource in the Azure portal to see your monitoring data.

Please refer SO Thread , Configuration Options and Kusto query for more information.

Appreciate the answer and comment on the question, they will prove to be a good resource for whoever comes across this question in future. However, a more pointed answer to this situation is needed. I was able to achieve the conditional, time based, verbose logging for my application by the following approach:

  1. Create an alert in azure portal pointing to the azure resource in use.
  2. Configure that alert's action group to call a controller action method, selecting webhook as the action type.
  3. Inside your controller action method, change the logging level setting to verbose logging for desired period of time, and reset it back to non-verbose after that. (I used non blocking Thread.sleep() for this)
  4. Enjoy the automation :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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