Data Collection: Trace Providers and Event Tracing with PerfView

How to Trace Providers and Event Tracing with PerfView?

As far as complexity goes a lot of the times we need to interact with the OS at a deep level calling various functions within APIs from different libraries. 
There comes a time when you need to trace the exact values pushed and returned through functions in order to understand why you run into failures. I think we've all wondered at times how low level tracing works behind the scenes.

Trace Providers

A  trace provider  is a component of a user-mode application or kernel-mode driver that uses Event Tracing for Windows (ETW) technology to generate trace messages or trace events. Typically, the trace events and messages report discrete actions of the provider. Reading a record of the events helps you to understand what the provider is doing in actual operating conditions.

A  trace session  can include more than one trace provider. This is especially useful for tracing drivers or applications that implement more than one provider component, as well as for tracing multiple drivers or applications that interact.

To start a trace session with more than one trace provider, you must specify the  control GUIDs  of all of the desired providers in the GUID (.guid extension) or control file that you submit to a  trace controller. The trace messages generated by the providers are interspersed in the event trace log (.etl) file.
 

Required tools

  1. PerfView - https://www.microsoft.com/en-us/download/details.aspx?id=28567
  2. Windows Events Provider Explorer - https://lallouslab.net/2016/01/25/windows-events-providers-explorer/

Our example

In order to integrate and query  Active Directory Domain Services (ADDS) API calls for various things like obtaining the groups of a particular user in order to import or authenticate.
For this to happen we need to establish communication between the Orchestrator and the Domain controller hosting the Active Directory where the user's group is. This involves a function (DsGetDcName) to get the name of the domain controller and passing it onto other parts of our code which throw the following exception: 

Error retrieving AD security groups  for   USERNAME.System.DirectoryServices.AccountManagement.PrincipalOperationException: Information about the domain could not be retrieved (1212).
		<div class="line number2 index1 alt1" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;outline: 0px;overflow: visible;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;white-space: nowrap;"><code class="c# spaces" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;">&nbsp;&nbsp;&nbsp;</code> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">at DomainControllerInfo System.DirectoryServices.AccountManagement.Utils.GetDcName(</code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">string</code> <span uipath_custom_id="30">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">computerName,<span uipath_custom_id="31">&nbsp;</span> </code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">string</code> <span uipath_custom_id="32">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">domainName,<span uipath_custom_id="33">&nbsp;</span> </code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">string</code> <span uipath_custom_id="34">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">siteName,<span uipath_custom_id="35">&nbsp;</span> </code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">int</code> <span uipath_custom_id="36">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">flags)</code></div>

		<div class="line number3 index2 alt2" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;outline: 0px;overflow: visible;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;white-space: nowrap;"><code class="c# spaces" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;">&nbsp;&nbsp;&nbsp;</code> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">at PrincipalContext System.DirectoryServices.AccountManagement.SDSCache.GetContext(</code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">string</code> <span uipath_custom_id="37">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">name, NetCred credentials, ContextOptions contextOptions)</code></div>

		<div class="line number4 index3 alt1" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;outline: 0px;overflow: visible;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;white-space: nowrap;"><code class="c# spaces" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;">&nbsp;&nbsp;&nbsp;</code> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">at<span uipath_custom_id="38">&nbsp;</span> </code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">object</code> <span uipath_custom_id="39">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">System.DirectoryServices.AccountManagement.AuthZSet.get_CurrentAsPrincipal()</code></div>

		<div class="line number5 index4 alt2" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;outline: 0px;overflow: visible;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;white-space: nowrap;"><code class="c# spaces" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;">&nbsp;&nbsp;&nbsp;</code> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">at T System.DirectoryServices.AccountManagement.FindResultEnumerator&lt;T&gt;.get_Current()</code></div>

		<div class="line number6 index5 alt1" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;outline: 0px;overflow: visible;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;white-space: nowrap;"><code class="c# spaces" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;">&nbsp;&nbsp;&nbsp;</code> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">at<span uipath_custom_id="40">&nbsp;</span> </code> <code class="c# keyword" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: bold !important;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(51, 102, 153) !important;">object</code> <span uipath_custom_id="41">&nbsp;</span> <code class="c# plain" style="font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: auto;line-height: auto;margin: 0px;outline: 0px;overflow: visible;padding: 0px;right: auto;text-align: left;top: auto;vertical-align: baseline;width: auto;box-sizing: content-box;font-weight: normal;font-style: normal;font-size: 14px;min-height: inherit;color: rgb(0, 0, 0) !important;">System.DirectoryServices.AccountManagement.FindResultEnumerator&lt;T&gt;.System.Collections.IEnumerator.get_Current()</code></div>

		<div class="line number7 index6 alt2" style="margin: 0px;padding: 0px 1em 0px 0px;border-radius: 0px;background: 0px center;border: 0px;bottom: auto;float: none;height: auto;left: