Extending Nodetrace

Common Scenarios

Nodetrace APIs

Nodetrace provides several APIs developers can use to add logging in their own code. This is powerful, as it doesn't suffer the same limitations as infolog and doesn't hit the database at all.

circle-check

This basic usage of Nodetrace allows logging complicated jobs that may throw exceptions. The using block is helpful as it captures logs even if exceptions are thrown and not caught in this block (helpful in tts blocks.

//By default, this logs: company, userid, starttime, endtime, duration
using(var scope = new AGCNodetraceScopeFactory("CustomJobName"))
{
    //Job code here
    
    //This will add a single 'Log' custom dimension in Application Insights
    //It is helpful because it will not roll back if an exception is thrown
    scope.Log("Something happened!");
    scope.Log("Something happened AGAIN!");
    
    // Get the log string if needed
    scope.GetLogStr("\r\n");
    
    scope.SetProperty("CustomKey", "Any string you want to log.");
    
    //If it throws an exception it will still log.
    // logging is sent once the using block is exited.
}
circle-check

The first scenario is logging custom events, perhaps in custom X++ code or as a way to log errors that are hard to track down in base code. This is an example of logging when payments fail to process successfully. This can be applied however a developer needs to log to Application Insights.

circle-check

The second scenario is adding performance logging to a retail service, which is pinged by the RCSU when using cPOS/mPOS. This scenario uses the AGCNodetraceScopeFactory which is a wrapper implementing IDisposable so that logging always happens even if exceptions are thrown. IDisposable doesn't suffer the same issues as normal X++ try/catches that have different behaviors depending on the ttslevel.

This is a chain of command method, so it collects the original parameters used in invocation. Behind the scenes, several important pieces of data are collected by default:

  1. ActivityId

  2. Server Url and AOS name

  3. UserId (not obfusticated)

  4. Start and End times in ISO8601 string format

  5. Duration in milliseconds

  6. ttslevel

  7. Retry count

  8. Company

  9. Interactive or batch session

  10. Session Id

Additional parameters are captured using the AGCNodetraceScopeFactory::SetProperty method. There is also a AGCNodetraceScopeFactory::SetMeasurement method available.

circle-check

Third scenario is logging exceptions caught in X++. Here is an example of logging exceptions for later analysis.

Last updated