Procedure for Manually Applying Custom Instrumentation to Un-instrumented Methods in .NET Applications under the .NET Agent

Procedure for Manually Applying Custom Instrumentation to Un-instrumented Methods in .NET Applications under the .NET Agent

APM Insight .NET Agent automatically instruments the .NET framework related methods and collect the metrics. Custom instrumentation helps to view your own framework performance without changing your application code. It allows you to track your own application methods captured and displayed in the transaction traces. It will be helpful to identify the performance related issue, when you suspect the execution time is taken more by your own application method.

If your application has a method with large code blocks  or it has some external calls, custom instrumentation helps you to identify the root cause of the performance issue.   
Note: There are no restrictions on the number of methods that can be configured manually. You can configure more than 2000 methods, but only the first 2000 will be tracked and monitored. If the process is recycled, the instrumentation will be reset, and only the first 2000 methods will remain instrumented.


  1. Viewing your own framework or web application performance.
  2. To group method metrics/performance, we can name same component for multiple methods. For Example:
    1. Method1 : SampleComponent
    2. Method2 : SampleComponent
    3. Method3 : SampleComponent
    4. Note: If the SampleComponent takes 25% time in overall application, it means that the three methods defined for the component consumed 25% of overall performance.
  3. Tracking performance of any third party framework used in your application.

Configuring custom instrumentation

The data in the configuration file as defined by APM Insight is in json format. We can define the assembly name, class name and method name used in your own web application and also we can specify the component name for each methods. The agent reads the configured data and track the performance of the methods specified.
The custom instrumentation configuration file `custom_instrumentation.json` can be found in `C:\ProgramData\DotNetAgent` path. 

Syntax of the Custom Instrumentation data:

  1.   {
  2.     "AssemblyName1": {
  3.     "NameSpace.ClassName1": {
  4.       "MethodName1": "ComponentName"
  5.     },
  6.     "NameSpace.ClassName2": {
  7.       "MethodName1": "ComponentName",
  8.       "MethodName2": "ComponentName"
  9.     }
  10.   },
  11.   "AssemblyName2": {
  12.     "NameSpace.ClassName1": {
  13.       "*": "ComponentName"
  14.     },
  15.     "NameSpace.*": {
  16.       "MethodName1": "ComponentName",
  17.       "MethodName2": "ComponentName"
  18.     }
  19.   }
  1. AssemblyName:   Name of the DLL.
  2. NameSpace.ClassName:   Name of the Class including the namespace name.
  3. MethodName:   Name of the method to be monitored.
  4. ComponentName:  Component name for the method. If it is empty, the component name will be taken as POCO(Plain Old  CLR Object) by default.
Note: Providing * in place of ClassName or MethodName, will track all the methods in the classes of assembly. We need to add `enable.wildcardmatch=true` in `C:\ProgramData\DotNetAgent\apminsight.conf` file and restarting the `ManageEngine .NET Agent` to achieve this.

Custom instrumentation example:

In the following code sample, we use employee DLL which has a controller class, SalaryController, containing three methods.
  1. namespace Employee.Controllers
  2. {
  3.     public class SalaryController : Controller
  4.     {
  5.         public ActionResult ProcessPayRoll()
  6.         {
  7.            EmployeeSR.EmpServiceClient empServiceClient = new EmployeeSR.EmpServiceClient();
  8.            empServiceClient.ProcessPayroll(Context.EmpId);
  9.            return View();
  10.         }
  11.         public ActionResult GetSalaryAmount(int empId)
  12.         {
  13.            using(var conn = new SqlConnection(connString))
  14.            {
  15.                 conn.Open();
  16.                 var cmd = new SqlCommand("select Salary from Employee where id='" + id + "'", conn);
  17.                 ViewBag.SalaryAmount = cmd. ExecuteScalar();
  18.                 conn.Close();
  19.            }
  20.            return View();
  21.         }
  22.         public ActionResult GetSalaryPerMonth(string id)
  23.         {
  24.            int salary = GetSalaryPerYear();
  25.            ViewBag.Result  = salary / 12;
  26.            return View();
  27.         }
  28.     }
  29. }
The custom instrumentation configuration for the class as follows,
  1. {
  2.   "Employee": {
  3.     "Employee.Controllers.SalaryController": {
  4.       "ProcessPayRoll": "PAYROLL",
  5.       "GetSalaryAmount": "FETCH",
  6.       "GetSalaryPerMonth": "FETCH"
  7.     }
  8.   }
  9. }

The instrumented methods will be displayed with execution time under the APM -> Your APM App/Instance -> Traces Tab -> Graph View -> Traces Details.
  1. No need to restart IIS.
  2. We need to recycle the corresponding application pool after modifying the custom instrumentation file to take effect.

                    New to ADSelfService Plus?