Help APM APM Insight using .NET Agent APM Insight .NET Agent, Custom Instrumentation, Manual configuration

Configuring .NET Agent Custom Instrumentation Manually

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.   

Benefits

  • Viewing your own framework or web application performance.

  • To group method metrics/performance, we can name same component for multiple methods.

    • Example : 

      • Method1 : SampleComponent

      • Method2 : SampleComponent

      • Method3 : SampleComponent

      • If the SampleComponent takes 25% time in overall application, it means that the three methods defined for the component consumed 25% of overall performance.

  • 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 ProgramData/DotNetAgent path. 

Syntax of the Custom Instrumentation data,

{

  "AssemblyName1": {

    "NameSpace.ClassName1": {

      "MethodName1": "ComponentName"

    },

    "NameSpace.ClassName2": {

      "MethodName1": "ComponentName",

      "MethodName2": "ComponentName"

    }

  },

  "AssemblyName2": {

    "NameSpace.ClassName1": {

      "*": "ComponentName"

    },

    "NameSpace.*": {

      "MethodName1": "ComponentName",

      "MethodName2": "ComponentName"

    }

  }

} 

  • AssemblyName :   Name of the DLL.

  • NameSpace.ClassName :   Name of the Class including the namespace name.

  • MethodName :   Name of the method to be monitored.

  • 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 apminsight.conf file to achieve this.

 

Custom instrumentation example

 

In the following code sample, we use employee DLL which has a controller class, SalaryController, containing three methods.

 

namespace Employee.Controllers

{

    public class SalaryController : Controller

    {

        public ActionResult ProcessPayRoll()

        {

           EmployeeSR.EmpServiceClient empServiceClient = new EmployeeSR.EmpServiceClient();

           empServiceClient.ProcessPayroll(Context.EmpId);

           return View();

        }

 

        public ActionResult GetSalaryAmount(int empId)

        {

           using(var conn = new SqlConnection(connString))

           {

                conn.Open();

                var cmd = new SqlCommand("select Salary from Employee where id='" + id + "'", conn);

                ViewBag.SalaryAmount = cmd. ExecuteScalar();

                conn.Close();

           }

           return View();

        }

 

        public ActionResult GetSalaryPerMonth(string id)

        {

           int salary = GetSalaryPerYear();

           ViewBag.Result  = salary / 12;

           return View();

        }

    }

}

 

The custom instrumentation configuration for the class as follows,

{

  "Employee": {

    "Employee.Controllers.SalaryController": {

      "ProcessPayRoll": "PAYROLL",

      "GetSalaryAmount": "FETCH",

      "GetSalaryPerMonth": "FETCH"

    }

  }

}

 

The instrumented methods will be displayed with execution time under the trace tab as follows,

 

Note: 

  • No need to restart IIS.

  • We need to recycle the corresponding application pool after modifying the custom instrumentation file to take effect.


Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.

Help APM APM Insight using .NET Agent APM Insight .NET Agent, Custom Instrumentation, Manual configuration