Configuring the Profiler-Initiated Collector

Why use the Profiler-Initiated Collector (PIC) approach?

The PIC approach simplifies .NET application instrumentation by leveraging built-in .NET / .NET Core profiling. It lets the profiler start the collector automatically as a detached process, with settings provided via environment variables or a configuration file, and stops the collector when the profiled process ends.

In some environments, there is no straightforward place to start the Coverage Collector explicitly:

  • Docker – modifying the entry point or command script can be complex.

  • Azure / Azure DevOps – no way to start the collector before IIS or override the test runner.

  • PCF – background tasks complicate executing commands to stop the collector (aka BGTL).

To enable this feature, set the environment variable SL_PROFILER_INITIALIZECOLLECTOR=1 to instruct the SeaLights Profiler to initialize its collector.

Best Practice: For containerized environments where you prefer not to modify the image, mount a folder containing the SeaLights Agent and point the profiler to it via the mounted path.

Agent Setup

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

# .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_BUILDSESSIONID', "$SL_BSID", "Machine")
#[Environment]::SetEnvironmentVariable('SL_BUILDSESSIONIDFILE', "path\to\buildSessionId.txt", "Machine")
[Environment]::SetEnvironmentVariable('SL_TOKENFILE', "path\to\sltoken.txt", "Machine")
[Environment]::SetEnvironmentVariable('SL_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")

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.

circle-exclamation
circle-check

Common Options

Logging (Optional)

Logging helps diagnose issues related to the profiler or collector startup, configuration, and connectivity. You can enable and fine-tune logging by setting the following environment variables:

circle-info

For advanced logging capabilities — such as controlling verbosity levels, enabling performance monitoring, or limiting logs to the Collector only — refer to the Agent Logging Configuration section of the documentation.

Specific configurations

IIS/Windows

If your application is deployed on IIS, follow the steps below:

  • Don’t publish the application in single-file or portable mode.

1

Define the Environment Variables

Define all necessary environment variables using absolute paths:

circle-info

Optimizing Collector Usage Across Multiple IIS Sites

If your IIS server hosts multiple sites on the same machine, each application pool will, by default, start its own profiler and Coverage Collector. This can increase resource usage.

To reduce the number of active collectors, configure all profilers to connect to a single shared collector by adding the following environment variables to your existing configuration:

These settings ensure that all profilers share a single collector instance bound to the specified port, while unused collectors terminate quickly after a short inactivity period. This approach reduces system overhead and optimizes resource usage.

2

Set the Variables in the Windows Registry

You can update the IIS environment variables in the Windows Registry using either a manual approach or PowerShell commands; both methods achieve the same result.

Set the environment variables for the IIS services in the Windows Registry:

  • Open the registry keys Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS and Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC

  • Add a new Multi-String value named Environment

circle-exclamation
3

Restart the IIS Server to apply the changes

  • Restart the IIS Server using iisreset /restart

  • Access your web application once to wake it up and verify that profiling starts correctly.

circle-check

Kubernetes / Containerized Deployment

If you can’t modify the image:

  • Mount a shared volume with the agent binaries.

  • Set env vars in the app container (see below).

  • Optionally use an initContainer to fetch the agent dynamically.

Last updated

Was this helpful?