Skip to content

Meters are not collected if Native AOT compilation is turned on #111801

Closed
@bsdayo

Description

@bsdayo

Description

System.Diagnostics.Metrics.Meter related instruments (Counters etc.) are not collected when <PublishAot>true</PublihAot>

Reproduction Steps

Create a new console project targeting net9.0.

<!-- TestCounters.csproj -->

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>

</Project>
// Program.cs

using System.Diagnostics.Metrics;

var meter = new Meter("Test", "1.0.0");
var counter = meter.CreateCounter<int>("test.counter");

while (true)
{
    counter.Add(4);
    Thread.Sleep(1000);
}

Start dotnet-counters with the following command:

dotnet-counters monitor -n TestCounters --counters Test

Output:

Press p to pause, r to resume, q to quit.
    Status: Waiting for initial payload...

Name                                                                                                       Current Value

As shown, no meter data is collected.

If I comment out <PublishAot>true</PublishAot> is csproj, the data is collected without any issue:

Press p to pause, r to resume, q to quit.
    Status: Running

Name                                                                                                       Current Value
[Test]
    test.counter (Count)                                                                                          12

Expected behavior

Meters data is collected in Native AOT compilation.

Actual behavior

Meters data is not collected in Native AOT compilation.

Regression?

Targeting net8.0 produces the same problem.

Known Workarounds

No response

Configuration

.NET SDK:
 Version:           9.0.102
 Commit:            cb83cd4923
 Workload version:  9.0.100-manifests.43af17c7
 MSBuild version:   17.12.18+ed8c6aec5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions