Custom Instrumentation via .NET Core agent API

Track custom methods or frameworks in your .NET Core application with APM Insight .NET Core agent API. You can track exceptions and errors in your custom class or methods by adding the agent API inside the methods or class that needs to be monitored.

Follow the below given instructions to instrument.

This is be supported from the agent nuget package version 4.6.0

Installation Instructions:

  1. Install APM Insight .NET Core agent
  2. Add the Site24x7 .NET Core agent API from the nuget package manager in your web application or in the dependent library projects. 
  3. The class Site24x7.AgentAPI contains the methods to track the performance of your methods or frameworks. 
  4. Include the method Site24x7.AgentAPI.CreateTracker(thisObject, methodName, componentName) to track the performance of a code block or method for a transaction.

Syntax:

The following method illustrates how to add a snippet.

public int YourMethod(string param1, string param2, bool param3)
{
using (Site24x7.AgentAPI.CreateTracker(this, "YourMethodName", "YourComponentName"))
{
// Your application code goes here
..............................
}
}

Example

public int ConvertToRupee(string param1, string param2, bool param3)
{
using (Site24x7.AgentAPI.CreateTracker(this, "ConvertToRupee", "CONVERTER"))
{
// Your application code goes here
..............................
}
}

The execution time of the code inside the using block will be calculated and shown under the method name ConvertToRupee.

Before Instrumentation:

After Instrumentation:

Tracking Exceptions in your application:

The method Site24x7.AgentAPI.TraceError(exception) helps to track the exceptions occurred in your code for a transaction.

Sample:

The following method illustrates how to add a snippet.

public int YourMethod(string param1, string param2, bool param3)
{
try
{
// Your application code goes here
..............................
}
catch (System.Exception ex)
{
Site24x7.AgentAPI.TraceError(ex);
}
}

The exception will be captured for a transaction and will be shown under the Traces tab.

Note:

  1. If the method that your are tracking is the first call in async/separate thread, it will be considered as a root method of the transaction. In this case it will be shown under the background transactions tab.
  2. You can use this method to track your asynchronous background services.
  3. If it is under a http transaction scope it will be shown under the trace of the particular transaction.
Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.