Application Insights is used by many organisations for logging, recording telemetry and leveraging it to detect and diagnose exceptions and application performance issues. Some of the core telemetry types it provides are:
- Trace (logging)
- Simple Telemetry
Out of the Box Telemetry
So how can we leverage Application Insights (AI) if we are using Mule? Great news! We can take some of the out of the box AI functionality to send logging (trace and exception telemetry) to AI without barely lifting a finger. We can also send JMX metrics with some lightweight configuration. Juicy low hanging fruit!
Microsoft provide an easy to use log4j appender for app insights. I won’t go into the detail here. It’s pretty straightforward, and will either appear as trace or exception types depending on the severity level. Added bonus: Any custom properties that you have in the context of your logging gets propagated seamlessly to AI.
Any JMX metrics you want to send to AI is as easy as configuring the performance counters in the ApplicationInsights.xml config.
Mule is no different, and sending common Mule counters such as average processing time or the number of processed events can be done with config similar to the below snippet. Historical data for our JMX beans – tick.
<PerformanceCounters> <Jmx> <Add objectName="Mule.azureconnectorapp:type=Flow,name="azureconnectorappFlow"" attribute="AverageProcessingTime" displayName="Mule - Flow Avg Processing Time" /> <Add objectName="Mule.azureconnectorapp:type=Flow,name="azureconnectorappFlow"" attribute="ProcessedEvents" displayName="Mule - Flow Number of Processed Event" /> </Jmx> </PerformanceCounters>
Custom Connector Time
The basic functionality gives us a lot without too much effort, but what if we want fine grained control? Drum roll. Introducing the Application Insights custom connector, complete with purple lightbulb icon. The processors are aligned with the core telemetry types that Application Insights provides.
Allows for simple logging messages to be sent to AI, along with specified severity level. Any custom properties may also be provided.
Allows for simple telemetry for a single name-value pair, metric. Ideal for storing simple counters.
Track an event. In its simplest form this just means providing the event name. This can be useful for providing simple counters in AI as to how often a specific type of event has occurred. Additionally both properties and metrics may also be supplied to give richer insights into the event.
Unsurprisingly, this processor sends the exception telemetry to AI. As with track event, the developer has the option of providing extra properties and metrics.
Track HTTP Request
Thus far, the request processor has not been created (not that it won’t be). This is due to the fact I was seeking to provide a simple hook for implicitly and transparently sending http request telemetry, whenever Mule makes an outbound HTTP request, rather than use an explicit processor. To this end I have leveraged Mule server notifications.
So there ya go. With very little effort, useful application telemetry can be pushed to Application Insights from your Mule application and greater control over the telemetry can be achieved via MuleSoft’s DevKit.