We just released the very first preview of Application Insights
for the ASP.NET 5
web applications. You can find the NuGet on nuget.org
and will allow you to monitor server requests and exceptions for your application as well as collect end user information and browser page performance.
Please follow this getting started guide
to onboard your ASP.NET 5 application to Application Insights.
ASP.NET application model was changed drastically with the new generation of ASP.NET. One of the big changes is dependency injection
that became a first class citizen. This changed the way you interact with telemetry SDK in ASP.NET 5 web applications.
As you may notice, Application Insights SDK for ASP.NET 5 applications takes dependency on the same "basic API" NuGet
that is used for the classic ASP.NET application monitoring today. It uses the same telemetry types, data contracts and channel however, there is one important difference - for ASP.NET 5 applications singleton
will not be initialized - you'll need to use dependency injection instead.
describes how to use Application Insights SDK for classic ASP.NET applications today. Code you'll typically write looks like this:
var tc = new TelemetryClient();
This code assumes some magic. Specifically that
will be initialized with the proper Instrumentation Key so it will know where to send event. Technically it is equivalent to this code when global singleton
passed to constructor:
var tc = new TelemetryClient(TelemetryConfiguration.Active);
This code will NOT work with ASP.NET 5 Application Insights SDK.
The very nature of ASP.NET 5 is to avoid singletons and use dependency injection instead. This wiki page
explains how you can get
class using dependency injection to track your events.
First, you'll need to get an instance of
. Suppose you need to track event from your home controller. You'll need to create a constructor that accepts
as an argument:
public class HomeController : Controller
private TelemetryClient telemetry;
public HomeController(TelemetryClient telemetry)
this.telemetry = telemetry;
Now you can use this telemetry client to track events and other custom telemetry:
public IActionResult Index()
As all the source code and history of this SDK development is available on GitHub
you may find how implementation of SDK evolved over time moving from singleton-based approach to the one based on dependency injection. We will be happy to hear your ideas, and feedback. Just file an issue
and tell us what you think.