Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eerhardt opened this issue Aug 13, 2024 · 9 comments
Open

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

eerhardt opened this issue Aug 13, 2024 · 9 comments
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@eerhardt
Copy link
Contributor

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

@eerhardt eerhardt added the bug Something isn't working label Aug 13, 2024
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Aug 13, 2024
@vishweshbankwar vishweshbankwar added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Aug 14, 2024
@vishweshbankwar
Copy link
Member

@eerhardt - OTLP exporter part is WIP #5731

@cijothomas
Copy link
Member

@rajkumar-rangaraj will continue/take-over the WIP PR to make this in 1.10

@cijothomas
Copy link
Member

Can be closed as duplicate of #5730 as 5730 will remove the dependency on protobuf, and that'll indirectly fix this issue too.

@eerhardt
Copy link
Contributor Author

Can be closed as duplicate of #5730 as 5730 will remove the dependency on protobuf, and that'll indirectly fix this issue too.

What about any other size issues beyond protobuf? For example, the Regex dependency I listed above.

@cijothomas
Copy link
Member

Re-opening as there are other things beyond protobuf that needs a revisit.
Removing 1.10 milestone as only protobuf is planned to be addressed for 1.10

@cijothomas cijothomas reopened this Sep 17, 2024
@cijothomas cijothomas removed this from the 1.10.0 milestone Sep 17, 2024
@cijothomas
Copy link
Member

So if that Regex is called often, it will slow down the app compared to a "normal" .NET app.

That particular one is not in hot path. Its only called when ActivitySource is created, not for every Activity creation.

@eerhardt
Copy link
Contributor Author

That particular one is not in hot path. Its only called when ActivitySource is created, not for every Activity creation.

The size of the app isn't affected whether it is on the hot path or not.

@cijothomas
Copy link
Member

That particular one is not in hot path. Its only called when ActivitySource is created, not for every Activity creation.

The size of the app isn't affected whether it is on the hot path or not.

That reply was only a response to the “slow down the app” part, not the size issue.

@rajkumar-rangaraj
Copy link
Contributor

Starting from version 1.11.0-rc.1 of OpenTelemetry.Exporter.OpenTelemetryProtocol, we have removed the dependency on google.protobuf and Grpc packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

No branches or pull requests

5 participants