Skip to content

Adding OpenTelemetry to a native AOT app adds a lot of app size #5785

@eerhardt

Description

@eerhardt

Package

OpenTelemetry

Package Version

Package Name Version
OpenTelemetry.Extensions.OpenTelemetryProtocol 1.9.0
OpenTelemetry.Extensions.Hosting 1.9.0
OpenTelemetry.Extensions.AspNetCore 1.9.0
OpenTelemetry.Extensions.Http 1.9.0
OpenTelemetry.Extensions.Runtime 1.9.0

Runtime Version

net9.0

Description

Adding OpenTelemetry to our native AOT'd ASP.NET Core "TodosApi" app in aspnet/Benchmarks#2014 shows the app size increase from 18.1 MB to 22.2 MB. About half of that size is from the OTLP Exporter. If I remove the OTLP Exporter, it drops back down to 20.0 MB.

For loo

Steps to Reproduce

dotnet publish the app before and after aspnet/Benchmarks#2014. Measure the app size in bin\Release\net9.0\win-x64\publish.

Expected Result

The app size change should be as minimal as possible.

Actual Result

The app gets about 22% larger when enabling OTel.

Additional Context

Using https://github.com/MichalStrehovsky/sizoscope, you can get some insight into what is taking all the size.

The first thing that jumps out to me is the usage of Regex:

image

This is coming from

if (state.Sources.Any())
{
// Validation of source name is already done in builder.
if (state.Sources.Any(s => WildcardHelper.ContainsWildcard(s)))
{
var regex = WildcardHelper.GetWildcardRegex(state.Sources);

The unfortunate thing about this is not only app size, but also on native AOT'd apps, Regex's that don't use the source generator are always interpreted. So if that Regex is called often, it will slow down the app compared to a "normal" .NET app.

For the OTLP Exporter, it looks like most of the app size is coming from Grpc:

image

and from generic collections of structs:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:OpenTelemetryIssues related to OpenTelemetry NuGet packagepkg:OpenTelemetry.Exporter.OpenTelemetryProtocolIssues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions