Integrating with Application Insights

by

Matthew Boulton

December 1, 2021

10 Min

reads

In this blog post we’re going to cover how you can use railtown.ai to get extra value from the telemetry you are already collecting with Application Insights.


First off, if you are using a logging framework, like Serilog, to collect logs and then forward them to Application Insights via a sink, then you can simply plug in railtown.ai as an additional sink for Serilog. This approach works for NLog and Log4Net as well and has been covered in a previous article so we won’t cover that here.


However, if Application Insights is your only source of telemetry, you can add Railtown as a Telemetry Processor. This means it is registered with the Application Insights TelemetryConfiguration and all telemetry that is sent to Application Insights goes through the railtown.ai processor as well. 


For more information about telemetry processors, please see this article: https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#filteringadd 


There are a number of ways of setting up Application Insights and choosing the right approach depends upon which version of .NET you are using. In this post, we’ll cover integrating with an ASP.NET Core web app. 


(If you’re using .NET framework and ApplicationInsights.config, the set up is very easy and you can read about that on our Support site: Using Application Insights to send logs (notion.so)


ASP.NET Core


Before we start, you’ll need a Railtown Key. You can get this from the Configuration section of the railtown.ai website. 



If you don’t already have a railtown.ai account, sign up now.


From the configure project page, go to the logs section and copy the contents of the RailtownKey node from the Application Insights xml configuration.


Install Nuget Packages


Next, you’ll need to add the ApplicationInsights.Railtown nuget package to your project: NuGet Gallery | ApplicationInsights.Railtown 1.3.0


Additionally, if you added Application Insights to your web application via the Azure Portal, you’ll need to add Microsoft’s ApplicationInsights.AspNetCore package as well: NuGet Gallery | Microsoft.ApplicationInsights.AspNetCore 2.19.0



Startup.cs


If you were already using the ApplicationInsights ASP.NET Core package, you should see a line like this inside StartUp.cs:


services.AddApplicationInsightsTelemetry();


The railtown.ai telemetry processor will be added in the same place, usually the ConfigureServices method:


public void ConfigureServices(IServiceCollection services)

{

     // ...

    services.AddApplicationInsightsTelemetry();

    services.AddSingleton(new RailtownTelemetryProcessorOptions() { 

        // put the Railtown Key here (or retrieve it from configuration like appsettings.json)        

        RailtownKey = "" 

     });

    services
        .AddApplicationInsightsTelemetryProcessor<RailtownTelemetryProcessorWithOptions>();

 }


The railtown.ai telemetry processor uses the options pattern so you will inject the Railtown Key via an options class. Add the RailtownKey value you obtained right at the beginning of this process. The snippet above shows how you’d put the key right in source code, but it’s good practice to retrieve this from configuration instead. You should treat your Railtown Key as a password and never check it into source code. You can read more about the Options pattern here: Options pattern in ASP.NET Core | Microsoft Docs


Now your application is configured to send Application Insights logs to railtown.ai. Railtown will automatically receive any events captured by Application Insights from these sources:


ILogger.Log() 

ITelemetryClient.TrackException() 

ITelemetryClient.TrackTrace() 

throw Exception // when not caught


To configure other types of .NET projects or to troubleshoot, please visit our support page here: Using Application Insights to send logs (notion.so)


I hope this has demonstrated how easy it is to use your existing Application Insights instrumentation to send logs to railtown.ai.


If you don’t already have a railtown.ai account sign up and let us help you improve the quality of your software and increase your developer velocity.


Keep reading

Root CauseHow AI Can Detect Software Bugs and Root Cause Analysis

Software bugs can be a significant source of frustration for developers and users alike. These errors in code can lead to crashes, data loss, and other issues that can negatively impact the user experience. Identifying and resolving software bugs is crucial for ensuring the quality and reliability of software applications. Artificial intelligence (AI) advances have made it possible to detect and diagnose software bugs more quickly and accurately than ever before

by

Marwan Haddad

March 29, 2023

5 Min

reads

AppInsightsHow AI Can Help Your Company Save Time on Creating Release Notes

With our Release Notes solution, you can save time for your team by generating all of your release notes automatically. What’s more, our product will give you the freedom of choosing the final format for all of your release notes, be it a summary, a short list, or a full page.

by

Marwan Haddad

February 6, 2023

3 Min

reads

Root CauseMachine Learning for Solving Root Cause Application Errors & Failures

In today's world, even a single application error could have significant consequences for both businesses and individual developers. From lost revenue and damaged reputation to disrupted services and frustrated customers, the cost of not addressing bugs in your code can be quite high.

by

Marwan Haddad

January 18, 2023

5 Min

reads