Skip to content

Commit

Permalink
Xiaomi7732 patch 4 (#75)
Browse files Browse the repository at this point in the history
* Update README.md

* Add example for hosting startup for ASP.NET Core 3.x apps

* Update configurations

* Update reference versions for examples to 2.1.0-*
  • Loading branch information
xiaomi7732 authored Jan 28, 2020
1 parent a09092a commit e7644d1
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 46 deletions.
44 changes: 32 additions & 12 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ All other ways document here: [Configuration in ASP.NET Core](https://docs.micro

Here lists all supported configurations.

| Key | Value/Types | Default Value | Description |
|---------------------------|-------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| BufferSizeInMB | Integer | 250 | Circular Buffer size. For 2 minutes session, it usually generates less than 200MB traces. Reduce the size for saving resources, increase the size for longer sessions. |
| Duration | TimeSpan | 00:02:00 | The duration of a session. |
| Interval | TimeSpan | 00:58:00 | The interval between sessions. |
| InitialDelay | TimeSpan | 00:00:00 | Delay before starting the very first session after the application starts up. |
| ProvideAnonymousTelemetry | Boolean | true | Sends anonymous telemetry data to Microsoft to make the product better when sets to true. |
| IsDisabled | Boolean | false | Kill switch to turn off Profiler. |
| IsSkipCompatibilityTest | Boolean | false | Bypass the check of platform compatibility testing to turn Profiler on by force. This is introduced mainly for internal use for evaluation and might cause unexpected result. |
| SkipUpload | Boolean | false | Skip uploading the traces to the back-end. Notice: Skipping uploading will always preserve the trace file. |
| PreserveTraceFile | Boolean | false | The trace file will be deleted once uploaded by default. Set this to true when you want to keep the local trace files. |
| Key | Value/Types | Default Value | Description | |
|-----------------------------------|-------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| BufferSizeInMB | Integer | 250 | Circular Buffer size. For 2 minutes session, it usually generates less than 200MB traces. Reduce the size for saving resources, increase the size for longer sessions. | |
| Duration | TimeSpan | 00:02:00 | The duration of a session. | |
| InitialDelay | TimeSpan | 00:00:00 | Delay before starting the very first session after the application starts up. | |
| ConfigurationUpdateFrequency | TimeSpan | 00:00:05 | The frequency for configuration updates for triggers or on demand profiling. This configuration decides how frequent the agent pulls configurations from the server. Optional, default value is 5 seconds | |
| ProvideAnonymousTelemetry | Boolean | true | Sends anonymous telemetry data to Microsoft to make the product better when sets to true. | |
| RandomProfilingOverhead | Float | 0.05 | The overhead for random profiling. The rate, in form of percentage, is used to calculate the time of profiling in average per hour. Basically, n = (60 * overhead rate) / profiling-duration. Default value is 0.05. | |
| IsDisabled | Boolean | false | Kill switch to turn off Profiler. | |
| IsSkipCompatibilityTest | Boolean | false | Bypass the check of platform compatibility testing to turn Profiler on by force. This is introduced mainly for internal use for evaluation and might cause unexpected result. | |
| SkipUpload | Boolean | false | Skip uploading the traces to the back-end. Notice: Skipping uploading will always preserve the trace file. | |
| PreserveTraceFile | Boolean | false | The trace file will be deleted once uploaded by default. Set this to true when you want to keep the local trace files. | |
| SkipEndpointCertificateValidation | Boolean | false | The value to skip the certificate validation to establish SSL communication with the Endpoint. It is **strongly recommended** to keep this the default value. | |

## Sets the logging level for Profiler

Expand Down Expand Up @@ -102,4 +104,22 @@ Here's a complete example of `appsettings.json`:
"InstrumentationKey": "application-insights-instrumentation-key"
}
}
```
```

## Application Insights Connection String

Application Insights connection string is also supported (For Profiler 2.1.0-beta1 or above) in configuration. For example:

```jsonc
{
...
"ServiceProfiler": {
...
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=your-instrumentation-key;IngestionEndpoint=https://anotheringestionEndpoint.io/;..."
},
}
```

A proper connection string could be found in the Application Insights Resource overview page of the Azure Portal, right below the `Instrumentation Key` field.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Application Insights Profiler for Asp.Net core on Linux App Services

## Blocking issue
## Announcement

* The server side issue of [#68](https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/issues/68) have been addressed.
* Profiler 2.1.0-beta1 is [available now](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.1.0-beta1). Read [What's new](./docs/WhatIsNew2_0.md) and [Migrate to Application Insights Profiler 2.0](./docs/MigrateTo2_0.md). Follow the example of [quick start](./examples/QuickStart3_0/Readme.md) if you are building a new app service.

## Announcement
* [Break change] Application Insights Profiler 2.1.0-* depends on [Application Insights SDK for ASP.NET Core 2.12.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.12.0) and above. It will be referenced implicitly.

* Profiler 2.0.0-beta5 is [available now](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta5). Read [What's new](./docs/WhatIsNew2_0.md) and [Migrate to Application Insights Profiler 2.0](./docs/MigrateTo2_0.md). Follow the example of [quick start](./examples/QuickStart3_0/Readme.md) if you are building a new app service.
* [New Feature] Hosting startup for ASP.NET Core 3.x application is supported for 2.1.0-beta1 and above. Refer to [readme](examples/HostingStartupCLR3/Readme.md) for how to use it.

* Recent bug fixes:
* Sampling requests to avoid recording large amount of similar requests. [#64](../../issues/64)
* Trace uploader size has been reduced to 5.7M from 10M. [#70](../../issues/70).
* Skip SSL configuration is now honored. [#69](../../issues/69).
* Reduce uploader size by having targeted binaries. [#70](../../issues/70)
* Application Insights connection string is supported. Check out the usage in [Configurations](./Configurations.md#Application-Insights-Connection-String).

## Description

Expand Down Expand Up @@ -67,7 +66,7 @@ Reference [ValuesController.cs](./examples/EnableServiceProfilerInVSCLR2_2_Win/E
```shell
dotnet add package Microsoft.ApplicationInsights.AspNetCore
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.0.0-*
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.1.0-*
```
_Note: Find the latest package from the [NuGet.org here](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/)._
Expand Down Expand Up @@ -142,10 +141,12 @@ You have been start to run the the WebApi with Profiler on.
* [The call tree filter](https://github.com/Azure/azure-diagnostics-tools/blob/master/Profiler/CallTreeFilter.md).
## Supported Versions
The profiling technology is based on .NET Core runtime. We do not support applications run on .NET Framework. See the table below for supported runtime.
| Application Insights Profiler | Windows | Linux |
|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------|
| [2.1.0-beta1](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.1.0-beta1) | Experimental support for .NET Core App 2.2, 3.0, 3.1 | Supported for .NET Core App 2.2, 3.0, 3.1 |
| [2.0.0-beta5](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta5) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.2, 3.0 |
| [2.0.0-beta4](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta4) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.2, 3.0 |
| [2.0.0-beta3](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta3) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.2, 3.0 |
Expand Down
22 changes: 6 additions & 16 deletions docs/MigrateTo2_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.0.0-*
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore --version 2.1.0-*
```

* To use package manager:
Expand All @@ -26,21 +26,11 @@ There are changes in the configurations. Refer to [What's new](./WhatIsNew2_0#Ne

And that's it.

## Stop using hosting startup
## Update to use the new hosting startup

Hosting startup is not supported for .NET Core 3.0 in 2.0.0-beta.
Hosting startup is supported for .NET Core 3.0 in 2.1.0-beta1 or above.

1. **Stop** setting environment variable: **ASPNETCORE_HOSTINGSTARTUPASSEMBLIES**=Microsoft.ApplicationInsights.Profiler.AspNetCore
1. Enable Profile through the code in `Startup.cs` like this:
1. **Stop** setting environment variable specific to .NET Core 2.x: **ASPNETCORE_HOSTINGSTARTUPASSEMBLIES**=Microsoft.ApplicationInsights.Profiler.AspNetCore
2. **Use** the environment variable: **ASPNETCORE_HOSTINGSTARTUPASSEMBLIES**=Microsoft.ApplicationInsights.Profiler.HostingStartup30

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers();
// Adding the following lines to enable application insights and profiler.
services.AddApplicationInsightsTelemetry();
services.AddServiceProfiler();
}
```
Read [this post](../examples/HostingStartupCLR3/Readme.md) for more details.
2 changes: 1 addition & 1 deletion examples/EnableServiceProfilerCLR2_1/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 1.1.6-*
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.1.0-*

# Restore & publish the app
RUN dotnet publish -c Release -o out
Expand Down
2 changes: 1 addition & 1 deletion examples/EnableServiceProfilerCLR2_1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To enable Service Profiler, NuGet package needs to be installed and proper envir
```docker
...
# Adding a reference to hosting startup package
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 1.1.6-*
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.1.0-*
...
# Light up Application Insights for Kubernetes
ENV APPINSIGHTS_INSTRUMENTATIONKEY YOUR_APPLICATION_INSIGHTS_KEY
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 1.1.6-*
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.1.0-*

# Restore & publish the app
RUN dotnet publish -c Release -o out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="1.1.6-*" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.1.0-*" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.*" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="1.1.6-*" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.1.0-*" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="1.1.6-*" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.1.0-*" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions examples/HostingStartupCLR3/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
obj/
global.json
2 changes: 2 additions & 0 deletions examples/HostingStartupCLR3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace ServiceProfiler.EventPipe.DockerApp30HS.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 void SimulateDelay()
{
// Delay for 200ms to 5s to simulate a bottleneck.
Thread.Sleep((new Random()).Next(200, 5000));
}
}
}
29 changes: 29 additions & 0 deletions examples/HostingStartupCLR3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy everything for build
COPY . ./

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

# Restore
RUN dotnet restore

# Publish
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

# Setup environment variable for application insights instrumentation key
ENV APPINSIGHTS_INSTRUMENTATIONKEY=#YOUR-APPINSIGHTS_INSTRUMENTATIONKEY#

# Setup environment variable for hosting startup assembly
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.ApplicationInsights.Profiler.HostingStartup30

WORKDIR /app
COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "ServiceProfiler.EventPipe.DockerApp30HS.dll"]
26 changes: 26 additions & 0 deletions examples/HostingStartupCLR3/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 ServiceProfiler.EventPipe.DockerApp30HS
{
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>();
});
}
}
Loading

0 comments on commit e7644d1

Please sign in to comment.