Skip to content

Commit

Permalink
Add example for Profiler for Windows (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomi7732 authored Jan 4, 2019
1 parent 1760ad1 commit ebae2dc
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnableSPInVSWin", "EnableSPInVSWin\EnableSPInVSWin.csproj", "{65B77662-6F74-422C-B8DE-33845708A227}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{65B77662-6F74-422C-B8DE-33845708A227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65B77662-6F74-422C-B8DE-33845708A227}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65B77662-6F74-422C-B8DE-33845708A227}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65B77662-6F74-422C-B8DE-33845708A227}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AC0B2E7-A842-4AA6-82FB-262496ED214C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
"Version": "8.14.11009.1",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?LinkID=798432"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EnableSPInVSWin.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<ApplicationInsightsResourceId>/subscriptions/41dd6365-42d0-4631-b6f1-6f38a08f0248/resourcegroups/EnableSPInVSWin/providers/microsoft.insights/components/EnableSPInVSWin</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/41dd6365-42d0-4631-b6f1-6f38a08f0248/resourcegroups/EnableSPInVSWin/providers/microsoft.insights/components/EnableSPInVSWin</ApplicationInsightsAnnotationResourceId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="1.1.4-private-201812171811" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace EnableSPInVSWin
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace EnableSPInVSWin
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add this line to enable Service Profiler
services.AddServiceProfiler();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseMvc();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ServiceProfiler": {
"SkipUpload": true
},
"AllowedHosts": "*",
"ApplicationInsights": {
"InstrumentationKey": "4e0746b4-7da3-4972-b300-036432bf379c"
}
}
56 changes: 56 additions & 0 deletions examples/EnableServiceProfilerInVSCLR2_2_Win/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Enable Application Insights Profiler for ASP.NET Core 2.2 Applications

For Application Insights Profiler 1.1.4-beta1 and above, profiling on Windows is supported as **an experimental feature** for ASP.NET Core 2.2 and above applications.

This document describes how to do it in Visual Studio.

## Create the Project

Create a ASP.NET Core **2.2** WebAPI project, give it a name, for example `EnableSPInVSWin`:

![Create project dialog](./.media/001_CreateProject.png)

## Enable Application Insights

Enable application insights by using the menu: `Add` | `Application Insights Telemetry ...` and follow the wizard until Application Insights is fully configured:

![Application Insights configured](./.media/003_AI_Enabled.png)

## Add NuGet package for Application Insights Profiler

Search the NuGet packages using keywords of `Application Insights Profiler`, making sure `Include Prerelease` is checked:

![Add NuGet package of Application Insights Profiler for ASP.NET](./.media/005_NuGets.png)

## Enable Application Insights Profiler by code

In [Startup.cs](./EnableSPInVSWin/Startup.cs), add the following code to enable Application Insights Profiler:

```csharp
public void ConfigureServices(IServiceCollection services)
{
// Add this line to enable Service Profiler
services.AddServiceProfiler();
// ...
}
```

## Debugging

Start Debugging the code using **Kestrel**:

![Start debugging using Kestrel](./.media/006_DebuggingKestrel.png)

Due to [issue#31](https://github.com/Microsoft/ApplicationInsights-Profiler-AspNetCore/issues/31), debugging using **IIS Express** will be supported in the later release (ETA: 1.1.4-beta2).

You will see logs like it below in the `Output` window:

![Profiler debug logging](./.media/007_ServiceProfilerLogging.png)

Now you can [deploy the application to Azure as an app service](https://docs.microsoft.com/en-us/azure/app-service).

## Known issues

* [Issue #31](https://github.com/Microsoft/ApplicationInsights-Profiler-AspNetCore/issues/31): ConvertTraceToEtlxValidator shall follow trace's path to avoid permission issue.

* The trace shown in the Azure Portal is noisy.

0 comments on commit ebae2dc

Please sign in to comment.