This project uses the New Relic .NET agent to demonstrate the reporting of code level metrics (CLM).
There is a .NET Core 3.1 ASP.NET Core MVC based web application contained in the AspNetCoreMvc
directory. This application is designed to create web transactions with custom instrumented segments.
By running the demo, the application will be launched and
daemonized and a tester.sh shell script will perform curl
commands that generate web traffic to exercise all traced Ruby methods.
The following class files define methods that will be invoked and produce code level metrics.
Controllers/AgentsController.cs: A basic ASP.NET Core ControllerHelpers.cs: A simple class that has a pair of static methods and instance methods that build a string that will be display in the MVC Views.
This class has 3 Controler Actions that are exercised by the demo, create, destroy, and show.
These produce the following transactions and metrics:
WebTransaction/MVC/Agents/CreateDotNet/AgentsController/CreateDotNet/AspNetCoreMvc.Helpers/CustomMethodOneDotNet/AspNetCoreMvc.Helpers/CustomMethodTwoDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodOneDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodTwo
WebTransaction/MVC/Agents/DestroyDotNet/AgentsController/DestroyDotNet/AspNetCoreMvc.Helpers/CustomMethodOneDotNet/AspNetCoreMvc.Helpers/CustomMethodTwoDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodOneDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodTwo
WebTransaction/MVC/Agents/ShowDotNet/AgentsController/ShowDotNet/AspNetCoreMvc.Helpers/CustomMethodOneDotNet/AspNetCoreMvc.Helpers/CustomMethodTwoDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodOneDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodTwo
The Helpers.cs file defines the AspNetCoreMvc.Helpers class.
This class contains a few additional methods that are instrumented using the .NET Agent's API.
The custom helpers file defines 2 staic methods, CustomStaticMethodOne and
CustomStaticMethodTwo, and 2 instance methods, CustomMethodOne,
and CustomMethodTwo
Both *One methods call their respective *Two method to create a nested segment.
The 4 methods produce the following New Relic metric names:
DotNet/AspNetCoreMvc.Helpers/CustomMethodOneDotNet/AspNetCoreMvc.Helpers/CustomMethodTwoDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodOneDotNet/AspNetCoreMvc.Helpers/CustomStaticMethodTwo
This demo can be run in a few different ways:
- It has a dockerfile that will build and run the application on Linux
- It can be built in Visual Studio, published and run
- It can be built with
dotnet build, published and run
- Docker
- .NET Core 6.0 SDK
- Visual Studio
- Clone this repository
- Place an extracted copy of the
.NET Core Linux versionof Agent's files in thenewrelicdirectory. 3a. If running in PROD:export NEW_RELIC_LICENSE_KEY=<YOUR_LICENSE_KEY>; export NEW_RELIC_HOST=collector.newrelic.com3b. If running in STAGING: After the build runexport NEW_RELIC_LICENSE_KEY=<YOUR_LICENSE_KEY>; export NEW_RELIC_HOST=staging-collector.newrelic.com - From
CodeLevelMetricsDemodirectory the Rundocker-compose up -d --build - You can exercise the app by going to
https:/localhost:8888and browsing around the UI.
- Clone this repository
- Open the solution,
CodeLevelMetricsDemo\CodeLevelMetricsDemo.sln - Rebuild the solution
- Right-click on the
AspNetCoreMvcproject and selectPublish - Publish the project using the
FolderProfile - Install the agent from the test MSI
- Start Powershell and change to the
CodeLevelMetricsDemo\publis\AspNetCoreMvcdirectory (must be done AFTER installing the agent to pick up the env vars) - Run
AspNetCoreMvc.exe - You can exercise the app by going to
https:/localhost:5001and browsing around the UI.
- Install the agent from the test MSI
- Clone this repository
- Run Powershell and change directory to the cloned repo
- Run
dotnet publish .\CodeLevelMetricsDemo.sln - Change to the
CodeLevelMetricsDemo\publis\AspNetCoreMvcdirectory (must be done AFTER installing the agent to pick up the env vars) - Run
AspNetCoreMvc.exe - You can exercise the app by going to
https:/localhost:5001and browsing around the UI.