1
votes

How can I configure Solr logs to get sent to Azure Application Insights?

I see can use a Log4J appender. https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-trace-logs

Solr is an open source project, and I don't compile it myself, I just use the distribution.

How can I drop in Application Insights/Log4J appender, without recompiling having installed the SDK? I just want to configure the logs to get sent to application insghts, for effectively a 3rd party application. And configure the instrumentation key.

I'm normally a C# dev, but familiar with Log4Net. So appologies if this is simple in Java Log4J. Not been able to find a post for this scenario so posting here.

Using Solr 6.6.

1
Have you seen Configuring Logging in the Solr reference guide? It's using log4j2, and you can add any .jars in the lib directories defined in your solr configuration file.MatsLindh
Thanks, yes I read that page, but didn't see anything on referencing other jars? I presume possible, but can't see a detailed guide.Ian
See Lib directives in solrconfig for how to give specific paths to load jars fromMatsLindh
thanks, that link was broken but found the page - lucene.apache.org/solr/guide/6_6/…Ian

1 Answers

4
votes

It takes a lot less configuration than you'd expect, and most of the info is hidden away in the link that you've already got: https://docs.microsoft.com/en-gb/azure/azure-monitor/app/java-trace-logs

First, go download the jar files from https://github.com/Microsoft/ApplicationInsights-Java/releases. You'll want applicationinsights-logging-log4j1_2-2.3.0 and applicationinsights-core-2.3.0. Put these in the server/lib folder and Solr will load them automatically for you.

Next you''ll need to add a new appender for app insights into your log4j.properties file

# Appinsights
log4j.appender.aiAppender=com.microsoft.applicationinsights.log4j.v1_2.ApplicationInsightsAppender
log4j.appender.aiAppender.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.aiAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n

You also need to add this aiAppender to the log4j.rootLogger list in the same file (it'll probably look something like this: log4j.rootLogger=INFO, file, CONSOLE, aiAppender)

Finally, you need an ApplicationInsights.xml file, which you can get an example of from here https://docs.microsoft.com/en-gb/azure/azure-monitor/app/java-get-started#2-add-the-application-insights-sdk-for-java-to-your-project

Drop this in the server/resources folder, set your instrumentation key and you're good to go!