Help Docs

Custom Instrumentation for .NET Core Agent Added via NuGet Package

Track custom methods or frameworks in your application and monitor their performance with the .NET core agent from NuGet, especially in console and Windows service applications built with .NET core.

Note

This will be supported from the agent NuGet package version 5.4.0

Follow the below-given instructions to configure the custom instrumentation.

Instructions to track the performance of your method

  1. Install the agent as per the instructions.
  2. The class Site24x7.Agent.Span contains the methods to track the performance of your methods or frameworks.
    Note

    After adding the agent package as per the instructions, the class Site24x7.Agent.Span is accessible in all the classes/methods within the application project.

  3. Create a 'using' statement 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.Agent.Span span = new Site24x7.Agent.Span("YourClassName", "YourMethod", "POCO"))
{
// Your application code or Your other method calls...
}
}

Example

public int ConvertToRupee(string param1, string param2, bool param3)
{
using (Site24x7.Agent.Span span = new Site24x7.Agent.Span("ToolController", "ConvertToRupee", "POCO"))
{
// 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.
  • In the case of console or Windows service applications, when the tracked method is the first method to be hit in the scope, the agent will take this method name as the transaction name.

Before Instrumentation


After Instrumentation


Tracking exceptions in your application

The method Site24x7.AgentAPI.TraceError(exception) helps to track the exceptions that 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.Agent.API.TraceError(ex);
}
}

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

Note

  • If the method that you 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.
  • You can use this method to track your asynchronous background services.
  • If it is under an HTTP transaction scope, it will be shown under the trace of the particular transaction.

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!