Skip to content

feat(native): add opt-in out-of-process crash handling - #5999

Draft
jpnurmi wants to merge 22 commits into
mainfrom
jpnurmi/feat/native-backend
Draft

jpnurmi wants to merge 22 commits into
mainfrom
jpnurmi/feat/native-backend

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Depends on sentry-native 1.0 (preload fixes and transport changes).

Description

Native AOT apps can opt into sentry-native's out-of-process native backend:

<SentryNativeBackend>native</SentryNativeBackend>

The sentry-crash daemon then sends native crashes while the app waits, instead of on the next launch. The publish output gets sentry-crash, its transport library and, on Windows, sentry-wer.dll. The default stays inproc.

This requires sentry-native 1.0 (submodule pinned to 1.0.0-beta.2 for now), which lets the SDK supply its own transport. The daemon loads sentry-crash-transport, a small Native AOT library built from the same NativeHttpClient as the app, so crash reports go through HttpClient with the app's proxy. The package ships the native variant for every RID alongside inproc.

Docs:

Issues

Closes #4867

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d06c319. Configure here.

Comment thread scripts/build-sentry-native.ps1 Resolved
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing breaks the lines a PR changes on purpose, one mutation at a time, and checks that a test fails each time. A changed line no test runs fails the check, and a mutant that survives the tests only warns. Full report

Sentry: tests caught 10 of 10 mutants on the changed lines

Sentry.Native.Transport: skipped, because no test project that runs here depends on it

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.31%. Comparing base (8dc3bb9) to head (ade792f).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/Platforms/Native/NativeHttpClient.cs 32.00% 17 Missing ⚠️
...rc/Sentry/Platforms/Native/NativeHttpClient.App.cs 0.00% 13 Missing ⚠️
src/Sentry/Platforms/Native/CFunctions.cs 54.54% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5999      +/-   ##
==========================================
+ Coverage   78.15%   78.31%   +0.15%     
==========================================
  Files         537      538       +1     
  Lines       20077    20160      +83     
  Branches     4041     4059      +18     
==========================================
+ Hits        15692    15788      +96     
+ Misses       3542     3525      -17     
- Partials      843      847       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread scripts/build-sentry-native.ps1 Resolved
@jamescrosswell

Copy link
Copy Markdown
Collaborator

Now that NativeHttpClient.cs is shared by the app and the daemon's transport library, could we give its header handling a unit test?

Rate limits are the main thing the HTTP transport adds, but nothing checks that X-Sentry-Rate-Limits and Retry-After reach sentry-native (here). The integration tests' mock server always accepts the upload, and the file-wide Stryker opt-out hides these lines from mutation testing.

Pulling the mapping out of Send and CreateRequest into methods that don't call into sentry-native would let us check that:

  • a response's X-Sentry-Rate-Limits and Retry-After come out with the right values;
  • on requests, content-length is dropped and Content-Type ends up on the content.

For mutation testing to count those tests, the opt-out would need to shrink to the parts that call sentry-native, or the helpers would move outside it.

jpnurmi added a commit to getsentry/sentry-docs that referenced this pull request Nov 25, 2026
Base automatically changed from jpnurmi/fix/native-preload to main November 25, 2026 11:15
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/native-backend branch 2 times, most recently from 6e43984 to 9acec05 Compare November 25, 2026 14:07
Comment thread integration-test/runtime.Tests.ps1 Resolved
jpnurmi and others added 12 commits November 25, 2026 17:56
sentry-native 1.0 removes `sentry_clear_crashed_last_run()`, because
`sentry_init()` consumes the crash marker itself, so stop calling it.

Its HTTP transport can also stream a file-backed body from an offset,
so `NativeHttpClient` now sends only the requested range of the file.
Build sentry-native with `SENTRY_TRANSPORT=custom`, the way the
downstream SDKs supply their own transports, and export
`sentry_transport_new_default()` from `NativeHttpClient` instead of
replacing the transport in `C.Init`. Native AOT apps resolve the
export through `UnmanagedEntryPointsAssembly`.

This prepares for the `native` backend, whose `sentry-crash` daemon
creates its transport through the same function.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Split `NativeHttpClient` into a shared core and host-specific parts,
and build the core into `sentry-crash-transport`, a Native AOT shared
library that `sentry-crash` will load to send crash reports with
`HttpClient`. The library exports `sentry_dotnet_transport_new()`,
which takes a table of the sentry-native functions it calls, because a
shared library can't link against the symbols inside `sentry-crash`.

In the daemon, the `HttpClient` honors the proxy and user agent from
the native options.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Add `-Backend native` to `build-sentry-native.ps1`. It builds
sentry-native with `SENTRY_BACKEND=native` through a small CMake
project that adds two sources to the `sentry-crash` target, the way
sentry-xbox adds its own:

- `sentry-crash-transport.c` supplies `sentry_transport_new_default()`
  by loading `sentry-crash-transport` from the executable's directory
  and passing it the sentry-native functions it calls.
- `sentry-preload.c` installs the daemon's crash handlers before the
  .NET runtime loads.

The script publishes the transport library for the RID, and deploys it
with `sentry-crash`, `sentry-wer.dll` on Windows, and the native
backend's libraries to `sentry-native/<rid>/native/`.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Native AOT apps can set the `SentryNativeBackend` property to `native`
to link sentry-native's `native` backend instead of `inproc`, and get
`sentry-crash`, its transport library and, on Windows, `sentry-wer.dll`
next to the app. The daemon sends crashes while the app waits, instead
of on the next launch.

Pack the native variant for every RID, build it locally and in CI, and
pass `SentryOptions.HttpProxy` to sentry-native so that the daemon uses
the same proxy.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Publish the transport without workload resolution, because it uses no
workloads and the `build-sentry-native` job doesn't install the
workload set that `global.json` pins. Stop when the publish or `lipo`
fails, instead of deploying an empty library.

Pack `sentry-wer.dll` and `sentry-crash-transport.dll` outside `lib/`
without NU5100, because they are native libraries for `sentry-crash`.

Co-authored-by: Claude Opus 5.5 <[email protected]>
The daemon got only the proxy address, so it couldn't send crash
reports through an authenticated proxy. Pass the credentials in the
proxy URL, and turn them back into `WebProxy.Credentials` in the
daemon.

Co-authored-by: Claude Opus 5.5 <[email protected]>
jpnurmi and others added 5 commits November 25, 2026 17:56
A spurious native crash sends a minidump envelope, which the mock
server can't print, so `Envelopes()` never sees it.

Co-authored-by: Claude Opus 5.5 <[email protected]>
The native backend tests relied on the publish test running first.
Run on their own, they tested an app published with the inproc
backend.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/native-backend branch from 2f358fc to 72c9ec8 Compare November 25, 2026 16:57
jpnurmi and others added 3 commits November 25, 2026 20:26
With the NuGet package folder inside the project directory, publish
kept the package-relative path of `sentry-crash` and its transport
library, where sentry-native doesn't find them.

Co-authored-by: Claude Opus 5.5 <[email protected]>
The test now also checks that sentry-native initializes. The image's
non-root user can't write the default database path in `/app`, so
the container runs in a writable working directory.

Co-authored-by: Claude Opus 5.5 <[email protected]>

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good.

The only question mark is the package size. Sentry.nupkg goes from 70 MB in main to 114 MB in this PR.

Everyone who references Sentry downloads that even though Most of them aren't Native AOT apps, and very few will set SentryNativeBackend=native.

#4867 originally suggested shipping out-of-process crash handling as a separate opt-in package. Is that worth revisiting? @ric-oliv thoughts?


// for the sentry-crash daemon of the native backend
if (options.HttpProxy is WebProxy { Address: { } address } proxy)
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang... Mutation Testing still reports the block removal on line 111 as NoCoverage. The // Stryker disable once all on line 119 only covers the sentry_options_set_proxy call, not the if block around it. Moving the marker up above the if on line 110 would silence it.

Alternatively, we could pull the URL building out and test this, the way AddHeader/GetHeaders are. Then the credential escaping gets a unit test... probably worth doing.

@jpnurmi

jpnurmi commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

The only question mark is the package size. Sentry.nupkg goes from 70 MB in main to 114 MB in this PR.

Everyone who references Sentry downloads that even though Most of them aren't Native AOT apps, and very few will set SentryNativeBackend=native.

#4867 originally suggested shipping out-of-process crash handling as a separate opt-in package. Is that worth revisiting? @ric-oliv thoughts?

I thought it wouldn't matter for the final deployment because it would only include necessary dependencies, but good point that it adds tens of MBs of development-time downloads even for non-NativeAOT apps.

Let's give it a try with the package split and see how it goes. The Native SDK is at 1.0.0-beta.2, and we still have at least a couple of weeks to polish and iterate this. 👍

Stryker can't compile mutants of a pattern that declares a variable,
so none of the mutants in `GetProxyUrl` were tested.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support opt-in crashpad (out-of-proc) for native crash handling in AOT applications

2 participants