'dotnet-trace won't collect managed code on a container

I'm having trouble tracing managed code of a .net core 3.1 application done inside a container.

I made a very simple .net core 3.1 program - this is the body of its Main:

for (int i = 0; i < 1000; i++) {
    Thread.Sleep(1000);
    Console.WriteLine("test");
}

Then after dotnet publish -c release I built an image (including dotnet-trace). This is the Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS sdk
RUN dotnet tool install --tool-path /tools dotnet-trace

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
COPY test-trace/bin/Release/netcoreapp3.1/publish app/
RUN mkdir /tools
COPY --from=sdk /tools /tools

ENTRYPOINT ["dotnet", "app/test-trace.dll"]

The image is deployed to a Kubernetes cluster:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-trace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-trace
  template:
    metadata:
      name: test-trace
      labels:
        app: test-trace
    spec:
      containers:
      - name: test-trace
        image: test-trace:latest
        imagePullPolicy: IfNotPresent
      restartPolicy: Always

Finally I ran dotnet-trace collect -p 1 --duration 00:00:00:10 inside the container, but when I opened the trace file in PerfView there was no managed code line in the call tree: PerfView of a trace inside a pod showing no managed code

On my workstation (Windows) the dotnet-trace output did contain a managed code line (although I ran it with dotnet test-trace.dll and not inside a container): PerfView of a trace from a Windows workstation showing managed code

I saw the .il suffix of the namespaces in the Windows trace file, but I don't know if it holds any clues to the solution. What am I missing? Thanks!

Update: I'll make a self-contained release and see if the trace file displays managed code (dotnet publish -r ubuntu-x64 -c Release --self-contained). If it works I'll post this as an answer.



Solution 1:[1]

The solution was to release a self-contained application - this way all the managed code symbols were addressed: dotnet publish -r ubuntu-x64 -c Release --self-contained

Also these variables were added to the Dockerfile:

ENV COMPlus_PerfMapEnabled=1
ENV COMPlus_EnableEventLog=1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 towel