1
0
Форкнуть 0

Add Application Insights into Web API project

This commit is contained in:
Sergey Kanzhelev 2015-04-21 19:42:55 -07:00
Родитель 6cab9de51c
Коммит 11ccc0f266
3 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.AspNet;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.ConfigurationModel;
namespace SampleWebAPIIntegration
{
@ -14,12 +16,21 @@ namespace SampleWebAPIIntegration
{
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
}
public IConfiguration Configuration { get; set; }
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
// Add Application Insights services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
@ -29,6 +40,19 @@ namespace SampleWebAPIIntegration
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Add the following to the request pipeline only in development environment.
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
// Set immediate delivery for Application Insights events.
app.SetApplicationInsightsTelemetryDeveloperMode();
}
// Add Application Insights monitoring to the request pipeline as a very first middleware.
app.UseApplicationInsightsRequestTelemetry();
// Add Application Insights exceptions handling to the request pipeline.
app.UseApplicationInsightsExceptionTelemetry();
// Configure the HTTP request pipeline.
app.UseStaticFiles();

Просмотреть файл

@ -0,0 +1,5 @@
{
"ApplicationInsights": {
"InstrumentationKey": "11111111-2222-3333-4444-555555555555"
}
}

Просмотреть файл

@ -3,10 +3,12 @@
"version": "1.0.0-*",
"dependencies": {
"Microsoft.ApplicationInsights.AspNet": "0.30.0.1-beta",
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4"
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4"
},
"commands": {