Skip to content

Support dotnet trace running in a sidecar container #810

Open
@MichaelSimons

Description

@MichaelSimons
  1. Run a containerized ASP.NET Core app within a container.
docker run -it -p 8000:80 --name aspnetapp mcr.microsoft.com/dotnet/core/samples:aspnetapp
  1. Build a image which contains the dotnet trace tool
FROM mcr.microsoft.com/dotnet/core/sdk:3.1

RUN dotnet tool install --global dotnet-trace

ENV PATH="${PATH}:/root/.dotnet/tools"
docker build -t dotnet/trace .
  1. Run the dotnet trace container
docker run -it --net=container:aspnetapp --pid=container:aspnetapp --cap-add ALL --privileged dotnet/trace
  1. Try to collect a trace of the ASP.NET Core app.

Expected Results:

I should be able to collect a dotnet trace. It is a common technique to utilize sidecar containers to profile applications running in another container. This allows you to profile existing application images without having to modify them. You can package all of your tools into a completely separate tools image.

An example of running perfcollect with this pattern is documented in this blog post

Actual Results

  1. dotnet trace ps does not match ps -aux
root@17be50bbd0fd:/# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  2.1 21288796 87672 pts/0  SLsl+ 22:36   0:03 dotnet aspnetapp.dll
root      1747  0.0  0.0   3988  3036 pts/0    Ss   23:19   0:00 bash
root      2231  0.0  0.0   7640  2704 pts/0    R+   23:23   0:00 ps -aux
root@17be50bbd0fd:/# dotnet trace ps
      2254 dotnet     /usr/share/dotnet/dotnet
      2272 dotnet-trace /root/.dotnet/tools/dotnet-trace
  1. The PID reported by dotnet trace cannot be found when running collect
root@17be50bbd0fd:/# dotnet trace collect -p 2254
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler     0xFFFFFFFFFFFFFFFF  Verbose(5)          --profile
Microsoft-Windows-DotNETRuntime         0x00000004C14FCCBD  Informational(4)    --profile

[ERROR] System.ArgumentException: Process with an Id of 2254 is not running.
   at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
   at System.Diagnostics.Process.GetProcessById(Int32 processId)
   at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration) in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 89
  1. The PID reported by ps is not a valid .NET app when running collect
root@17be50bbd0fd:/# dotnet trace collect -p 1
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler     0xFFFFFFFFFFFFFFFF  Verbose(5)          --profile
Microsoft-Windows-DotNETRuntime         0x00000004C14FCCBD  Informational(4)    --profile

[ERROR] System.PlatformNotSupportedException: Process 1 not running compatible .NET Core runtime
   at Microsoft.Diagnostics.Tools.RuntimeClient.DiagnosticsIpc.IpcClient.GetTransport(Int32 processId) in /_/src/Microsoft.Diagnostics.Tools.RuntimeClient/DiagnosticsIpc/IpcClient.cs:line 50
   at Microsoft.Diagnostics.Tools.RuntimeClient.DiagnosticsIpc.IpcClient.SendMessage(Int32 processId, IpcMessage message, IpcMessage& response) in /_/src/Microsoft.Diagnostics.Tools.RuntimeClient/DiagnosticsIpc/IpcClient.cs:line 84
   at Microsoft.Diagnostics.Tools.RuntimeClient.EventPipeClient.CollectTracing(Int32 processId, SessionConfiguration configuration, UInt64& sessionId) in /_/src/Microsoft.Diagnostics.Tools.RuntimeClient/Eventing/EventPipeClient.cs:line 80
   at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration) in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 104

Notes:

  1. I was using the dotnet trace version 3.1.57502+6767a9ac24bde3a58d7b51bdaff7c7d75aab9a65
  2. dotnet trace worked as expected if I added it within my application container. This required me to install to .NET SDK since it is a global tool.
  3. It is possible I am messed up something obvious here and this is something that is already supported 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    containersrelated to running/installing/configuring Diagnostics in a containerenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions