Sealights .NET Core agent - Configuring the Profiler-Initiated Collector

There are multiple cases when there is no suitable place in the pipeline to call explicit commands to set and start the Coverage Collector:

  • docker container requires changes to the entry point and replacing a single command with a more complicated script

  • Azure environment - there is no place where we can tell Azure to start the collector before the IIS worker

  • PCF environment also has some complications with stopping BGTL

  • Azure DevOps environment with TestSuits doesn’t allow to override the test runner command.

To avoid explicit execution of the collector, the profiler can start the detached process of the collector on initialization and connect to it without providing CLI args for the collector. All collector configurations should be set over env variables or using the configuration file. Once the profiled process is finished, the profiler will signal the collector to stop.

 

This scenario is valid only if the profiler is instructed to use the PIC feature over the env variable:

SL_PROFILER_INITIALIZECOLLECTOR = 1

When working with containers that you do not want to modify by adding the Sealights Agent to it, we recommend to mount a folder to thecontainer with the agent there and simply provide the path to the mounted directory.

Agent Setup

To instruct the profiler to start the collector, the target process should have a set of environmental variables:

Windows (Powershell)

Linux

Windows (Powershell)

Linux

# .Net Legacy [Environment]::SetEnvironmentVariable("COR_ENABLE_PROFILING", "1", "Machine") [Environment]::SetEnvironmentVariable("COR_PROFILER", "{01CA2C22-DC03-4FF5-8350-59E32A3536BA}", "Machine") [Environment]::SetEnvironmentVariable("COR_PROFILER_PATH_32", "path\to\SL.DotNet.ProfilerLib.Windows_x86.dll", "Machine") [Environment]::SetEnvironmentVariable("COR_PROFILER_PATH_64", "path\to\SL.DotNet.ProfilerLib.Windows_x64.dll", "Machine") # .NetCore [Environment]::SetEnvironmentVariable("CORECLR_ENABLE_PROFILING", "1", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER", "{01CA2C22-DC03-4FF5-8350-59E32A3536BA}", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_32", "path\to\SL.DotNet.ProfilerLib.Windows_x86.dll", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_64", "path\to\SL.DotNet.ProfilerLib.Windows_x64.dll", "Machine") [Environment]::SetEnvironmentVariable("SL_PROFILER_INITIALIZECOLLECTOR", "1", "Machine") [Environment]::SetEnvironmentVariable('SL_SESSION_BUILDSESSIONID', "$SL_BSID", "Machine") #[Environment]::SetEnvironmentVariable('SL_SESSION_BUILDSESSIONIDFILE', "path\to\buildSessionId.txt", "Machine") [Environment]::SetEnvironmentVariable('SL_SESSION_TOKENFILE', "path\to\sltoken.txt", "Machine") [Environment]::SetEnvironmentVariable('SL_SESSION_LABID', "$LAB_ID", "Machine") #[Environment]::SetEnvironmentVariable("SL_PROFILER_INCLUDEPROCESSFILTER", "*include*,*what*,*is*,*ne?ded*", "Machine") #Optional parameters #[Environment]::SetEnvironmentVariable("SL_PROFILER_EXCLUDEPROCESSFILTER", "*exclude*,*unnee?ed", "Machine") #[Environment]::SetEnvironmentVariable("SL_COVERAGECOLLECTOR_STARTUPINACTIVITYTIMEOUTSEC", "10", "Machine") #[Environment]::SetEnvironmentVariable("SL_COVERAGECOLLECTOR_IDLETIMEOUTSEC", "0", "Machine")
export CORECLR_ENABLE_PROFILING=1 export CORECLR_PROFILER="{3B1DAA64-89D4-4999-ABF4-6A979B650B7D}" export CORECLR_PROFILER_PATH_32="path\to\libSL.DotNet.ProfilerLib.Linux.so" export CORECLR_PROFILER_PATH_64="path\to\libSL.DotNet.ProfilerLib.Linux.so" export SL_PROFILER_INITIALIZECOLLECTOR = 1 export SL_SESSION_BUILDSESSIONID="$SL_BSID" #export SL_SESSION_BUILDSESSIONIDFILE="path\to\buildSessionId.txt" export SL_SESSION_TOKENFILE="path\to\sltoken.txt" export SL_SESSION_LABID="$LAB_ID" #export SL_PROFILER_INCLUDEPROCESSFILTER="*include*,*what*,*is*,*ne?ded*" #Optional parameters #export SL_PROFILER_EXCLUDEPROCESSFILTER="*exclude*,*unnee?ed" #export SL_COVERAGECOLLECTOR_STARTUPINACTIVITYTIMEOUTSEC=10 #export SL_COVERAGECOLLECTOR_IDLETIMEOUTSEC=0

If the process starts successfully, the profiler starts a connection to the collector using the same key. If the profiled process has child processes, they will reuse the same collector in most cases.

Ensure the variables specifying the profiler path are correct, given where you installed the agent binaries (for example: CORECLR_PROFILER_PATH_32=/usr/local/lib/libSL.DotNet.ProfilerLib.Linux.so)

At the successful completion of this step, you will see new entries appearing in the Cockpit > Live Agents Monitor: the testListener and a entity called Profiler with the version details of your application.

Logging (Optional)

If you want to enable logging you can add the following variables declaration.

Windows (Powershell)

Linux

Windows (Powershell)

Linux