diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/001_CreateProject.png b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/001_CreateProject.png new file mode 100644 index 0000000..30281f4 Binary files /dev/null and b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/001_CreateProject.png differ diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/003_AI_Enabled.png b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/003_AI_Enabled.png new file mode 100644 index 0000000..fdacea6 Binary files /dev/null and b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/003_AI_Enabled.png differ diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/005_NuGets.png b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/005_NuGets.png new file mode 100644 index 0000000..6cc0671 Binary files /dev/null and b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/005_NuGets.png differ diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/006_DebuggingKestrel.png b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/006_DebuggingKestrel.png new file mode 100644 index 0000000..74e3bc1 Binary files /dev/null and b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/006_DebuggingKestrel.png differ diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/007_ServiceProfilerLogging.png b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/007_ServiceProfilerLogging.png new file mode 100644 index 0000000..263cdb1 Binary files /dev/null and b/examples/EnableServiceProfilerInVSCLR2_2_Win/.media/007_ServiceProfilerLogging.png differ diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin.sln b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin.sln new file mode 100644 index 0000000..103dd36 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin.sln @@ -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 diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Connected Services/Application Insights/ConnectedService.json b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Connected Services/Application Insights/ConnectedService.json new file mode 100644 index 0000000..94232b3 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Connected Services/Application Insights/ConnectedService.json @@ -0,0 +1,7 @@ +{ + "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider", + "Version": "8.14.11009.1", + "GettingStartedDocument": { + "Uri": "https://go.microsoft.com/fwlink/?LinkID=798432" + } +} \ No newline at end of file diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Controllers/ValuesController.cs b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Controllers/ValuesController.cs new file mode 100644 index 0000000..6eff564 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Controllers/ValuesController.cs @@ -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> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult 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) + { + } + } +} diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/EnableSPInVSWin.csproj b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/EnableSPInVSWin.csproj new file mode 100644 index 0000000..36ddecc --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/EnableSPInVSWin.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.2 + InProcess + /subscriptions/41dd6365-42d0-4631-b6f1-6f38a08f0248/resourcegroups/EnableSPInVSWin/providers/microsoft.insights/components/EnableSPInVSWin + /subscriptions/41dd6365-42d0-4631-b6f1-6f38a08f0248/resourcegroups/EnableSPInVSWin/providers/microsoft.insights/components/EnableSPInVSWin + + + + + + + + + + + + + + diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Program.cs b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Program.cs new file mode 100644 index 0000000..1869681 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Program.cs @@ -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(); + } +} diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Startup.cs b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Startup.cs new file mode 100644 index 0000000..7700d16 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Startup.cs @@ -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(); + } + } +} diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.Development.json b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.json b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.json new file mode 100644 index 0000000..50a8c81 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/appsettings.json @@ -0,0 +1,14 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "ServiceProfiler": { + "SkipUpload": true + }, + "AllowedHosts": "*", + "ApplicationInsights": { + "InstrumentationKey": "4e0746b4-7da3-4972-b300-036432bf379c" + } +} \ No newline at end of file diff --git a/examples/EnableServiceProfilerInVSCLR2_2_Win/README.md b/examples/EnableServiceProfilerInVSCLR2_2_Win/README.md new file mode 100644 index 0000000..6ac0d34 --- /dev/null +++ b/examples/EnableServiceProfilerInVSCLR2_2_Win/README.md @@ -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.