Skip to content

Errors with sentry-native launching with Sentry.AspNetCore on Dockerized Native AOT builds on Linux #4127

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

Open
ionite34 opened this issue Apr 21, 2025 · 10 comments · May be fixed by #4188
Open
Labels
Bug Something isn't working Native

Comments

@ionite34
Copy link

ionite34 commented Apr 21, 2025

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0.201

OS

Linux

OS Version

alpine 3.21

Development Environment

Other

SDK Version

5.5.1

Self-Hosted Sentry Version

No response

Workload Versions

N/A

UseSentry or SentrySdk.Init call

N/A

Steps to Reproduce

  1. Using any minimal api AOT example, such as:
var builder = WebApplication.CreateSlimBuilder(args);

builder.Services.AddSentry();

var app = builder.Build();

api.MapGet("test", () => "Test Ok");

await app.RunAsync();
  1. Building with this Dockerfile:
FROM mcr.microsoft.com/dotnet/nightly/sdk:9.0.201-alpine3.21-aot AS build
WORKDIR /src

COPY --link . .
RUN dotnet publish -c Release -a linux-musl-x64 -o /app ./Project/Project.csproj
RUN rm /app/*.dbg /app/*.Development.json

FROM mcr.microsoft.com/dotnet/nightly/runtime-deps:9.0.3-alpine3.21-aot AS final
USER $APP_UID
EXPOSE 8080
EXPOSE 8081
ENV ASPNETCORE_URLS=http://+:8080

WORKDIR /app
COPY --link --from=build /app .
ENTRYPOINT ["./Project"]

Expected Result

Should be able to launch normally

Actual Result

Upon hitting endpoints we'll get a 500 error with:

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'sentry-native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 

Error loading shared library sentry-native.so: No such file or directory
Error loading shared library libsentry-native.so: No such file or directory
Error loading shared library sentry-native: No such file or directory
Error loading shared library libsentry-native: No such file or directory

   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x139
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
   at Sentry.Native.C.sentry_options_new() + 0x1f
   at Sentry.Native.C.Init(SentryOptions) + 0x1f
   at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2d
   at Sentry.SentrySdk.InitHub(SentryOptions) + 0x185
   at Sentry.SentrySdk.Init(Action`1) + 0x3a
   at Program.<<Main>$>d__0.MoveNext() + 0xde

Might be related to #4116 and #4102

An option to disable this sentry-native usage might be helpful for now since this is a blocker for us deploying Sentry at all on our Native AOT containers just for request exceptions logging and traces.

We're currently using https://www.nuget.org/packages/Microsoft.ApplicationInsights.aspnetcore on these containers, and despite build time trim warnings it still works fine so far in regards to capturing exceptions and traces.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 21, 2025
@ionite34 ionite34 changed the title Errors with sentry-native launching with Sentry.AspNetCore on Native AOT builds on Linux Errors with sentry-native launching with Sentry.AspNetCore on Dockerized Native AOT builds on Linux Apr 21, 2025
@bruno-garcia
Copy link
Member

bruno-garcia commented Apr 22, 2025

Thanks for raising this.

to unblock you, there is an option in MSbuild you can use DisableSentryNative if u set to false stops sentry from adding it.

We might rename that to SentryDisableNative but we'll keep it backward compatible at least until version 6.0 of the sdk.

Looks like this option was released yet so we'll put a release out asap to unblock you.

Other than that we need to debug this as this shouldn't be happening.

Are you using a proper nuget dependency? like adding sentry via nuget? is something possibly deleting our native libraries from the obj/bin folders?

@bruno-garcia
Copy link
Member

We'll ship a release tomorrow either with the option name. Or with the current solution so you can work around this.

But looking in more detail about the issue: /runtime-deps:9.0.3-alpine3.21-aot perhaps we don't have sentry-native in a way that's compatible with this? Is it a musl Linux situation? @vaind might have thoughts

Note the publish args: linux-musl-x64
We bundle these sentry-native static libs:

Image

linux-x64 is there, should that work on musl linux?
Does .NET look at linux-x64 when resolving the directoy? Or does it look at linux-musl-x64 and hence we need to build a new version and add to a new directory? @filipnavara might know this one.

@filipnavara
Copy link
Contributor

filipnavara commented Apr 22, 2025

Does .NET look at linux-x64 when resolving the directoy? Or does it look at linux-musl-x64 and hence we need to build a new version and add to a new directory?

I think you might need to build a new one. Even if it looked for the directory (which can be checked with the RID graph) the native binaries are generally not portable between different libc implementations.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 22, 2025
@vaind
Copy link
Collaborator

vaind commented Apr 23, 2025

We specify the path explicitly, so after adding the build, we'll also need to update this code:

<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and '$(RuntimeIdentifier)' == 'linux-x64'">
<DirectPInvoke Include="sentry-native" />
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\linux-x64\libsentry-native.a" />
<!-- See: https://github.com/dotnet/runtime/issues/97414 -->
<NativeSystemLibrary Include="curl" />
</ItemGroup>

@bruno-garcia
Copy link
Member

I think we need to make a release asap where we disable sentry-native if we detect RID is linux-musl

@bruno-garcia
Copy link
Member

Release finally done: https://github.com/getsentry/sentry-dotnet/releases/tag/5.6.0

Sorry took a minute. We had issues with our release automation.
You can disable it with:

<SentryNative>false</SentryNative>

@bruno-garcia
Copy link
Member

Good news, this got resolved in the native SDK:

Now, following his work on:

@jpnurmi
Copy link
Collaborator

jpnurmi commented May 14, 2025

Indeed, sentry-native has been fixed to support musl with all backends. The way sentry-dotnet builds sentry-native with -DSENTRY_BACKEND=inproc -DSENTRY_BUILD_SHARED_LIBS=0 makes it link to static libunwind.a to avoid deployment issues. The rest is about fixing the sentry-dotnet build system and CI to deal with linux-x64 vs. linux-musl-x64.

Edit: Fixes released in sentry-native 0.8.5.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 14, 2025
@jpnurmi jpnurmi linked a pull request May 14, 2025 that will close this issue
8 tasks
@Flash0ver Flash0ver added Bug Something isn't working Native labels May 15, 2025
@ionite34
Copy link
Author

Release finally done: 5.6.0 (release)

Sorry took a minute. We had issues with our release automation. You can disable it with:

false

Hm, just testing the disabling of sentry native now on 5.7.0, but I don't think it's working for a project depending on

<PackageReference Include="Sentry" Version="5.7.0" />
<PackageReference Include="Sentry.AspNetCore" Version="5.7.0" />

Tried the following:

<PropertyGroup>
    <DisableSentryNative>true</DisableSentryNative>
    <SentryNative>false</SentryNative>
</PropertyGroup>

<ItemGroup>
    <RuntimeHostConfigurationOption Include="Sentry.Native.IsEnabled" Value="false" />
</ItemGroup>

When we add the integration with

builder.Services.AddSentry();

Upon hitting any asp endpoint we still result in:

info: Microsoft.Hosting.Lifetime[14]
2025-05-20T19:15:47.895673863Z info: Microsoft.Hosting.Lifetime[0]
2025-05-20T19:15:47.895676531Z       Application started. Press Ctrl+C to shut down.
2025-05-20T19:15:47.895678952Z info: Microsoft.Hosting.Lifetime[0]
2025-05-20T19:15:47.895681456Z       Hosting environment: Production
2025-05-20T19:15:47.895683713Z info: Microsoft.Hosting.Lifetime[0]
2025-05-20T19:15:47.895686135Z       Content root path: /app
2025-05-20T19:15:50.443714670Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2025-05-20T19:15:50.443755105Z       Connection id "0HNCNQATQV04U", Request id "0HNCNQATQV04U:00000001": An unhandled exception was thrown by the application.
2025-05-20T19:15:50.443761672Z       System.DllNotFoundException: Unable to load shared library 'sentry-native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
2025-05-20T19:15:50.443765715Z       Error loading shared library sentry-native.so: No such file or directory
2025-05-20T19:15:50.443768372Z       Error loading shared library libsentry-native.so: No such file or directory
2025-05-20T19:15:50.443770701Z       Error loading shared library sentry-native: No such file or directory
2025-05-20T19:15:50.443772958Z       Error loading shared library libsentry-native: No such file or directory
2025-05-20T19:15:50.443775215Z       
2025-05-20T19:15:50.443777442Z          at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
2025-05-20T19:15:50.443779709Z          at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x139
2025-05-20T19:15:50.443790821Z          at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
2025-05-20T19:15:50.443793335Z          at Sentry.Native.C.sentry_options_new() + 0x1f
2025-05-20T19:15:50.443797552Z          at Sentry.Native.C.Init(SentryOptions) + 0x1f
2025-05-20T19:15:50.443799850Z          at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2d
2025-05-20T19:15:50.443802159Z          at Sentry.SentrySdk.InitHub(SentryOptions) + 0x176
2025-05-20T19:15:50.443805267Z          at Sentry.Extensions.Logging.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__0`1.<AddSentry>b__0_3(IServiceProvider c) + 0x41
2025-05-20T19:15:50.443807904Z          at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite, RuntimeResolverContext) + 0xf
2025-05-20T19:15:50.443810274Z          at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite, RuntimeResolverContext) + 0x64

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 20, 2025
@jamescrosswell
Copy link
Collaborator

@ionite34 that shouldn't be happening, logically. Setting <SentryNative>false</SentryNative> should result in FrameworkSupportsNative being set to false:

<FrameworkSupportsNative Condition="'$(SentryNative)' == 'false' or '$(SentryNative)' == 'disable'">false</FrameworkSupportsNative>

And that gets used to determine whether SentryNative is included... e.g. here:

<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and '$(RuntimeIdentifier)' == 'linux-x64'">
<DirectPInvoke Include="sentry-native" />
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\linux-x64\libsentry-native.a" />
<!-- See: https://github.com/dotnet/runtime/issues/97414 -->
<NativeSystemLibrary Include="curl" />
</ItemGroup>

Is it possible the logs that you're seeing are from an older build of your product that is still using an earlier version of the Sentry SDK?

If not, you could try running your build with the /bl parameter to get binary logs, so that you can dig into what's happening in your build. It may be that this property is being overwritten in a Directory.Build.props file or something somewhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Native
Projects
Status: No status
Status: No status
Development

Successfully merging a pull request may close this issue.

7 participants