Skip to content

AI Method 2

Ahmad Sattar edited this page Oct 24, 2019 · 8 revisions

2. Traces, exceptions and plugin execution as dependencies

Example configuration can be found here.

The second method of logging extends on the first by timing each execution and tracking them as dependencies, such that a timeline of plugin execution is formed in AI. We keep correlation of each trace item, but add a visual representation of our traces.
The timeline and logs would look like this: Trace timeline of method 2 Trace logs of method 2

Setting it up

Start by adding AI to your project and build, explained here.

  1. Copy DGTracingService and IDGTracingService into your plugins project (find it here under the Services folder)
  2. Insert your instrumentation key at the top of DGTracingService
    • It is also possible to fetch the instrumentation key with the OrganizationService that resides in the LocalPluginContext constructor step 4 uses
  3. Inside Plugin.cs Add the following attribute above the LocalPluginContext constructor
internal IDGTracingService DGTracingService {
    get;

    private set;
}
  1. Inside Plugin.css LocalPluginContext constructor below line containing this.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); add
this.TracingService = new DGTracingService(this.TracingService, this.PluginExecutionContext.CorrelationId);
this.DGTracingService = (IDGTracingService)this.TracingService;
  1. Add the following before the Try block in the Execute function inside Plugin.cs
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();
  1. Inside the Catch section of the Try/Catch/Finally section add this to the top
timer.Stop();
localcontext.DGTracingService.TraceException(e);
  1. Inside the finally section of the Try/Catch/Finally section add this to the top
timer.Stop();
localcontext.DGTracingService.TraceDependency(
    localcontext.PluginExecutionContext.MessageName,
    localcontext.PluginExecutionContext.PrimaryEntityName, 
    this.ChildClassName,
    startTime, timer.Elapsed);
  1. If you wish to show trace class names without namespace, add the following attribute above the Plugin constructor
protected string ChildClassNameSimple{
    get;
    private set;
}

And add this inside the Plugin constructor

this.ChildClassNameSimple = childClass.Name;
Clone this wiki locally