Skip to content

Commit

Permalink
Merge pull request #134 from xiaomi7732/dev/saars/2.2.0
Browse files Browse the repository at this point in the history
Dev/saars/2.2.0
  • Loading branch information
xiaomi7732 authored Mar 26, 2021
2 parents 7149d87 + a325b2d commit 7faf910
Show file tree
Hide file tree
Showing 20 changed files with 278 additions and 16 deletions.
18 changes: 15 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"label": "build QuickStart 3.1",
"command": "dotnet",
"type": "process",
"type": "shell",
"args": [
"build",
"${workspaceFolder}/examples/EnableServiceProfilerInVSCLR21/CLR21Example/CLR21Example/CLR21Example.csproj"
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"options": {
"cwd": "${workspaceFolder}/examples/QuickStart3_1/"
},
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
}
]
Expand Down
4 changes: 2 additions & 2 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To do that, in `appsettings.json`:
"Logging": {
"LogLevel": {
"Default": "Warning",
"ServiceProfiler": "Debug"
"Microsoft.ApplicationInsights.Profiler": "Debug"
}
}
}
Expand All @@ -88,7 +88,7 @@ Here's a complete example of `appsettings.json`:
"Logging": {
"LogLevel": {
"Default": "Warning",
"ServiceProfiler": "Debug"
"Microsoft.ApplicationInsights.Profiler": "Debug"
}
},
"AllowedHosts": "*",
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

## Announcement

* It is official! We are out of beta! Profiler 2.2.0 is published. Find the NuGet package: [2.2.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0)

## Previous announcements

* Profiler 2.2.0-beta7 is published. Find the NuGet package here: [2.2.0-beta7](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0-beta7).
* Remove the logging from the Uplaoder by default. ([#128 Application is starting and shutting down messages written when using profiler](https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/issues/128)).
* Some other small fixes.

## Previous announcements

* Profiler 2.2.0-beta6 is published. Find the NuGet package here: [2.2.0-beta6](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0-beta6).
* Fix the issue of Uploader not exit in the last release. Details: [#124](https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/issues/124).

Expand Down Expand Up @@ -37,7 +39,7 @@ dotnet new webapi

```shell
dotnet add package Microsoft.ApplicationInsights.AspNetCore
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.2.0-*
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
```

_Notice: .NET Core 2.2 is **out of support**, it is recommended to migrate your project to .NET 3.1. Refer to [.NET Core](https://dotnet.microsoft.com/download/dotnet-core) page for details. If you have to stay on .NET Core 2.2 for now, please this specific version of [`Microsoft.ApplicationInsights.AspNetCore v2.14`](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.14.0) alone with the profiler package._
Expand Down Expand Up @@ -68,7 +70,7 @@ To make it real, make use the following code to add some delay in the [WeatherFo
```csharp
using System.Threading;
...
private void SimulateDelay()
private static void SimulateDelay()
{
// Delay for 200ms to 5s to simulate a bottleneck.
Thread.Sleep((new Random()).Next(200, 5000));
Expand Down Expand Up @@ -102,6 +104,8 @@ In [appsettings.Development.json](examples/QuickStart3_0/appsettings.Development
}
```

* Alternatively, use a connection string like in [QuickStart3.1 example](./examples/QuickStart3_1/appsettings.Development.json).

* Run the WebAPI, generate traffic for profiling

To run your application locally:
Expand Down
5 changes: 5 additions & 0 deletions ReleaseNote.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Note

## 2.2.0

* Find the NuGet package: [2.2.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0).
* We are officially out of beta.

## 2.2.0-beta7

* Find the NuGet package here: [2.2.0-beta7](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0-beta7).
Expand Down
1 change: 1 addition & 0 deletions SupportMatrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The profiling technology is based on .NET Core runtime. We do not support applic

| Application Insights Profiler | Windows (Experimental support) | Linux |
|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|-----------------------------|
| [2.2.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0) | .NET Core App 3.1, .NET 5 | .NET Core App 3.1, .NET 5 |
| [2.2.0-beta7](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0-beta7) | .NET Core App 3.1, .NET 5 | .NET Core App 3.1, .NET 5 |
| [2.2.0-beta6](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.2.0-beta6) | .NET Core App 3.1, .NET 5 | .NET Core App 3.1, .NET 5 |
| 2.2.0-beta5 | .NET Core App 3.1, .NET 5 | .NET Core App 3.1, .NET 5 |
Expand Down
4 changes: 2 additions & 2 deletions docs/MigrateTo2_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ There are break changes between 1.x and 2.0 for Application Insights Profiler bu
* To use .NET Core CLI:

```shell
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore --version 2.2.0-*
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore --version 2.*
```

* To use package manager:

```shell
Install-Package Microsoft.ApplicationInsights.Profiler.AspNetCore -Version 2.2.0-*
Install-Package Microsoft.ApplicationInsights.Profiler.AspNetCore -Version 2.*
```

## Update the configurations
Expand Down
2 changes: 1 addition & 1 deletion examples/EnableServiceProfilerForContainerApp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
COPY . ./

# Adding a reference to hosting startup package
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.2.0-*
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.*

# Restore & publish the app
RUN dotnet publish -c Release -o out
Expand Down
2 changes: 1 addition & 1 deletion examples/HostingStartupCLR3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . ./

# Add additional nuget packages
RUN dotnet add package Microsoft.ApplicationInsights.AspNetCore --no-restore
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.2.0-* --no-restore
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.* --no-restore

# Restore
RUN dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion examples/HostingStartupCLR3/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ There are small tweaks needed to make it work.
# Add reference to the latest stable version of Application Insights for ASP.NET Core.
RUN dotnet add package Microsoft.ApplicationInsights.AspNetCore --no-restore
# Adding reference to Microsoft.ApplicationInsights.Profiler
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.2.0-* --no-restore
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.* --no-restore
```

As you already know, invoking `dotnet add` does nothing but update the project file. And running `COPY . ./` next will overwrite the change. To deal with it, copy everything before adding packages and do not copy it again later.
Expand Down
2 changes: 1 addition & 1 deletion examples/QuickStart3_0/QuickStart3_0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.2.0-*" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.*" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion examples/QuickStart3_0/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The latest Application Insights (2.8+) is required to run on .NET Core 3.0. And

```shell
dotnet add package Microsoft.ApplicationInsights.AspNetCore
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.2.0-*
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.*
```

### Update the code in `Startup.cs` to enable application insights and the profiler
Expand Down
47 changes: 47 additions & 0 deletions examples/QuickStart3_1/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace QuickStart3_1.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
SimulateDelay();
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}

private static void SimulateDelay()
{
// Delay for 500ms to 2s to simulate a bottleneck.
Thread.Sleep((new Random()).Next(500, 2000));
}
}
}
26 changes: 26 additions & 0 deletions examples/QuickStart3_1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

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

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
13 changes: 13 additions & 0 deletions examples/QuickStart3_1/QuickStart3_1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.*" />
</ItemGroup>


</Project>
53 changes: 53 additions & 0 deletions examples/QuickStart3_1/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Quick Start (.NET Core 3.1 WebAPI)

## Build the solution

Refer to the same steps to build a [WebAPI for .NET 3.0](../QuickStart3_0/Readme.md).

## To run this example locally

* Create an Application Insights resource in Azure, refer to [Create workspace-based resource](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-workspace-resource) for instructions.
* Note down the connection string.

* Update the connection string in [appsettings.Development.json](appsettings.Development.json).

```jsonc
{
...
"ApplicationInsights": {
"ConnectionString": "__ReplaceWithYourConnectionString__"
}
}
```

* Run the code

```shell
dotnet run
```

Example of a successful log locally:

```shell
> PS D:\Repos\profiler\examples\QuickStart3_1> dotnet run
info: Microsoft.ApplicationInsights.Profiler.Core.IServiceProfilerContext[0]
Profiler Endpoint: https://profiler.monitor.azure.com/
info: Microsoft.ApplicationInsights.Profiler.AspNetCore.ServiceProfilerStartupFilter[0]
Starting application insights profiler with instrumentation key: your-ikey-will-show-up-here
info: Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerProvider[0]
Service Profiler session started.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\Repos\fork-ai-profiler\examples\QuickStart3_1
info: Microsoft.ApplicationInsights.Profiler.Core.UploaderProxy.TraceUploaderProxy[0]
Finished calling trace uploader. Exit code: 0
info: Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerProvider[0]
Service Profiler session finished.
```
57 changes: 57 additions & 0 deletions examples/QuickStart3_1/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.Hosting;
using Microsoft.Extensions.Logging;

namespace QuickStart3_1
{
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)
{
services.AddControllers();
services.AddApplicationInsightsTelemetry();
services.AddServiceProfiler(profilerSettings =>
{
// Refer to https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/blob/main/Configurations.md for more settings.
profilerSettings.Duration=TimeSpan.FromSeconds(60);
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
15 changes: 15 additions & 0 deletions examples/QuickStart3_1/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace QuickStart3_1
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
Loading

0 comments on commit 7faf910

Please sign in to comment.