-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for Profiler for Windows (#32)
- Loading branch information
1 parent
1760ad1
commit ebae2dc
Showing
14 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+25.3 KB
examples/EnableServiceProfilerInVSCLR2_2_Win/.media/001_CreateProject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.67 KB
examples/EnableServiceProfilerInVSCLR2_2_Win/.media/003_AI_Enabled.png
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.
Binary file added
BIN
+5.9 KB
examples/EnableServiceProfilerInVSCLR2_2_Win/.media/006_DebuggingKestrel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.8 KB
examples/EnableServiceProfilerInVSCLR2_2_Win/.media/007_ServiceProfilerLogging.png
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
25
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
...SCLR2_2_Win/EnableSPInVSWin/Connected Services/Application Insights/ConnectedService.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Controllers/ValuesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/EnableSPInVSWin.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
25 changes: 25 additions & 0 deletions
25
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |