Skip to main content

.NET beta

This is a documentation for a new beta version of our new dotnet integration. It is based on dd-trace-dotnet.

The new features are:

  • support for memory profiling
  • support for wall (wall-clock) time profiling
  • support for exceptions profiling
  • support for dynamic tags

Supported .NET versions:#

  • .NET 6.0

Supported platforms#

Spy NameTypeLinuxmacOSWindowsDocker
dotnetspyembeddedโœ…

Running .NET profiler#

  1. Download Pyroscope.Profiler.Native.so and Pyroscope.Linux.ApiWrapper.x64.so from latest release

  2. Set the following required environment variables to enable profiler

PYROSCOPE_APPLICATION_NAME=rideshare.dotnet.appPYROSCOPE_SERVER_ADDRESS=http://localhost:4040PYROSCOPE_AUTH_TOKEN="psx-..." # optional auth tokenPYROSCOPE_PROFILING_ENABLED=1CORECLR_ENABLE_PROFILING=1CORECLR_PROFILER={BD1A650D-AC5D-4896-B64F-D6FA25D6B26A}CORECLR_PROFILER_PATH=Pyroscope.Profiler.Native.soLD_PRELOAD=Pyroscope.Linux.ApiWrapper.x64.so

Dynamic labels#

It is possible to add labels to the profiling data. These labels can be used to filter the data in the UI.

  1. Add dependency
dotnet add package Pyroscope
  1. Create a LabelSet and wrap a piece of code with Pyroscope.LabelsWrapper
var labels = Pyroscope.LabelSet.Empty.BuildUpon()    .Add("key1", "value1")    .Build();Pyroscope.LabelsWrapper.Do(labels, () =>{  SlowCode();});

Labels can be nested. For nesting LabelSets use LabelSet.BuildUpon on non-empty set.

var labels = Pyroscope.LabelSet.Empty.BuildUpon()    .Add("key1", "value1")    .Build();Pyroscope.LabelsWrapper.Do(labels, () =>{  var labels2 = labels.BuildUpon()    .Add("key2", "value2")    .Build();  Pyroscope.LabelsWrapper.Do(labels2, () =>  {    SlowCode();  });  FastCode();});

Configuration#

ENVIRONMENT VARIABLETypeDESCRIPTION
PYROSCOPE_PROFILING_LOG_DIRStringSets the directory for .NET Profiler logs. Defaults to /var/log/pyroscope/ .
PYROSCOPE_LABELSStringStatic labels to apply to an uploaded profile. Must be a list of key:value separated by commas such as: layer:api,team:intake.
PYROSCOPE_PROFILING_ENABLEDBooleanIf set to true, enables the .NET Profiler. Defaults to false.
PYROSCOPE_PROFILING_WALLTIME_ENABLEDBooleanIf set to false, disables the Wall time profiling. Defaults to true.
PYROSCOPE_PROFILING_CPU_ENABLEDBooleanIf set to false, disables the CPU profiling. Defaults to true.
PYROSCOPE_PROFILING_EXCEPTION_ENABLEDBooleanIf set to true, enables the Exceptions profiling (beta). Defaults to false.
PYROSCOPE_PROFILING_ALLOCATION_ENABLEDBooleanIf set to true, enables the Allocations profiling (beta). Defaults to false.
PYROSCOPE_PROFILING_LOCK_ENABLEDBooleanIf set to true, enables the Lock Contention profiling (beta). Defaults to false.