aspnetcore: Member-level trimming breaks ASP.NET tracing instrumentation
Description
Traces produced by OpenTelemetry instrumentation for ASP.NET (AddOpenTelemetryTracing) lack almost all expected data when running an application with member-level trimming enabled. AddHttpClientInstrumentation does not seem to be affected.
Reproduction Steps
Create a Kestrel server serving favicon.png. Set the following in the project file:
<TargetFramework>net7.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
Set up OpenTelemtry instrumentation for ASP.NET, send it to Jaeger (or use the console exporter).
Publish as self-contained for win-x64 (also reproducible for linux-musl-x64), run.
Send a GET request for /favicon.png.
Expected behavior
Span has the right display name and attributes.

Actual behavior
Span is for all intents and purposes empty.

Regression?
No response
Known Workarounds
Use <TrimMode>copyused</TrimMode>.
Configuration
Built with SDK 7.0.100-preview.5.22307.18.
On Windows 10 running the self-contained executable.
On Linux running in Docker with base mcr.microsoft.com/dotnet/runtime-deps:7.0.0-preview.5-alpine3.16.
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (13 by maintainers)
Verified as fixed with https://github.com/dotnet/aspnetcore/pull/42591.
@kerams You should assume nothing works with member level trimming by default in .NET. Anything that uses reflection that wasn’t explicitly designed to be trimmed will break. People that have been successful with trimming in general have been either lucky of very determined. .NET 7 is the first version where we’re officially trying to mark more of the framework with “this will break when you trim” or describe any reflection we do where possible.