Skip to content

digikare/ApplicationInsights-Profiler-AspNetCore

 
 

Repository files navigation

Application Insights Profiler for Asp.Net core on Linux App Services

Announcement

  • Profiler 2.1.0-beta3 is published. Please find the nuget package here: 2.1.0-beta3.

  • Profiler 2.1.0-beta2 is NOT recommended. There is a bug that impacts the ASP.NET Core application starting up. See bug #85 for details. Please wait for 2.1.0-beta3.

Previous announcements

Description

This is the project home page for Microsoft Application Insights Profiler for ASP.NET Core. The NuGet package can be found here.

Profiler Traces

Get Started

The following steps based are based on ASP.NET Core 2.2 project. Refer to Quick Start for more specific steps for ASP.NET Core 3.0 projects.

  • Create a WebApi project

    dotnet new webapi -n ProfilerEnabledWebAPI

To make it real, make use the following code to add some delay in the controllers to simulate the bottleneck:

using System.Threading;
...
private void SimulateDelay()
{
    // Delay for 200ms to 5s to simulate a bottleneck.
    Thread.Sleep((new Random()).Next(200, 5000));
}

And call it from the controller methods:

// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
    SimulateDelay();  // Bottleneck
    return new string[] { "value1", "value2" };
}

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

Reference ValuesController.cs for full code.

  • Add the NuGet packages

    dotnet add package Microsoft.ApplicationInsights.AspNetCore
    dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.1.0-*

    Note: Find the latest package from the NuGet.org here.

  • Create an Application Insights in Azure Portal, set Application Insights instrumentation key in appsettings.Development.json:

    {
        "ApplicationInsights": {
            "InstrumentationKey": "replace-with-your-instrumentation-key"
        }
    }
  • Enable Profiler in Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddApplicationInsightsTelemetry(); // Enable Application Insights telemetry
        services.AddServiceProfiler(); // Add this line of code to Enable Profiler
        ...
    }
  • Run the code:

    dotnet run

    And you will see the following logs, indicating Profiler is up and running:

    dbug: ServiceProfiler.EventPipe.AspNetCore.ServiceProfilerStartupFilter[0]
        Constructing ServiceProfilerStartupFilter
    dbug: ServiceProfiler.EventPipe.AspNetCore.ServiceProfilerStartupFilter[0]
        User Settings:
        {
            "BufferSizeInMB": 250,
        }
    dbug: ServiceProfiler.EventPipe.Client.Utilities.RuntimeCompatibilityUtility[0]
        Checking compatibility for Linux platform.
    dbug: ServiceProfiler.EventPipe.AspNetCore.ServiceProfilerStartupFilter[0]
        Pass Runtime Compatibility test.
    dbug: ServiceProfiler.EventPipe.Client.Schedules.TraceSchedule[0]
        Entering TriggerStart - initial: True.
    dbug: ServiceProfiler.EventPipe.Client.Schedules.TraceSchedule[0]
        Entering StartAsync, idle for the interval of 3000 ms.
    Hosting environment: Development
    Content root path: /mnt/d/ApplicationInsightsProfiler
    Now listening on: https://localhost:5001
    Now listening on: http://localhost:5000
    Application started. Press Ctrl+C to shut down.
    ...

You have been start to run the the WebApi with Profiler on.

  • Generate some traffic for traces by visiting during the 2 minutes profiling session:

    https://localhost:5001/api/values

Learn More

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 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 Experimental support for .NET Core App 2.2, 3.0 Supported for .NET Core App 2.2, 3.0
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 Experimental support for .NET Core App 2.2, 3.0 Supported for .NET Core App 2.2, 3.0
2.0.0-beta2 Experimental support for .NET Core App 2.2, 3.0 Supported for .NET Core App 2.2, 3.0
2.0.0-beta1 Experimental support for .NET Core App 2.2, 3.0 Supported for .NET Core App 2.2, 3.0
1.1.7-beta2 Experimental support for .NET Core App 2.2, 3.0 Supported for .NET Core App 2.1, 2.2, 3.0
1.1.7-beta1 Experimental support for .NET Core App 2.2. Supported for .NET Core App 2.1, 2.2
1.1.6-beta1 Experimental support for .NET Core App 2.2. Supported for .NET Core App 2.1, 2.2
1.1.5-beta2 Experimental support for .NET Core App 2.2. Supported for .NET Core App 2.1, 2.2
1.1.4-beta1 Experimental support for .NET Core App 2.2. Trace tree in the trace explorer looks very noisy. Supported for .NET Core App 2.1, 2.2
1.1.3-beta2 Not supported. Supported for .NET Core App 2.1, 2.2
1.1.3-beta1 Not supported. Supported for .NET Core App 2.1, 2.2
1.1.2-beta1 Not supported. Deprecated.
1.0.0-beta1 Not supported. Deprecated.

Examples

References

CAUTION

This is a documentation/sample repository. The LICENSE covers the content in this repository but does NOT cover the use of the product of Microsoft.ApplicationInsights.Profiler.AspNetCore. Please reference EULA-prerelease.md for any prerelase product and EULA-GA.md for any non-prerelease product.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

About

Application Insights Profiler sample and documentation

Resources

License

Stars

Watchers

Forks

Packages

No packages published