fix(ndk): Create outbox directory before writing crash envelopes#1889
Merged
Conversation
runningcode
marked this pull request as ready for review
July 21, 2026 08:56
runningcode
force-pushed
the
no/ndk-create-outbox-dir-before-write
branch
from
July 21, 2026 09:17
44e2e29 to
8372d2a
Compare
runningcode
force-pushed
the
no/ndk-create-outbox-dir-before-write
branch
from
July 21, 2026 09:26
374e9c0 to
5b135bb
Compare
The NDK layer writes crash envelopes through a custom transport that targets the head SDK's outbox path. Native init only creates its own `.sentry-native` database directory (a sibling of the outbox), and the envelope write does not create parent directories, so a missing outbox made the write fail silently and the crash report was lost. Create the outbox in the transport before each write, matching how the rest of sentry-native ensures its cache and external directories exist, and log if creation fails so the failure is diagnosable. This lets head SDKs create the outbox lazily without dropping native crash envelopes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sentry-native now creates the outbox directory itself before writing, so the sample no longer needs to create it up front. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
runningcode
force-pushed
the
no/ndk-create-outbox-dir-before-write
branch
from
July 21, 2026 09:34
5b135bb to
725e730
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1889 +/- ##
==========================================
+ Coverage 75.42% 75.75% +0.32%
==========================================
Files 92 92
Lines 21599 21966 +367
Branches 3807 3914 +107
==========================================
+ Hits 16291 16640 +349
- Misses 4438 4442 +4
- Partials 870 884 +14 🚀 New features to boost your workflow:
|
8 tasks
The previous approach called sentry__path_* and sentry__logger_log via extern declarations. Those symbols are internal to the core library and, unlike SENTRY_API-tagged ones, are not exported from the shared object the NDK links against, so the Android build failed to link with undefined symbol errors. Create the outbox directory directly with mkdir(2) instead. The NDK library is Android-only, so POSIX is always available, and log failures through __android_log_print rather than the unexported core logger. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jpnurmi
approved these changes
Jul 22, 2026
jpnurmi
reviewed
Jul 22, 2026
Comment on lines
+314
to
+316
| // sentry-native's path helpers are internal to the core library and not | ||
| // exported from the shared object we link against, so we create the outbox | ||
| // ourselves. Android is always POSIX, so mkdir(2) is all we need. |
Collaborator
There was a problem hiding this comment.
sorry about this, btw. it's not that easy to access sentry-native internals. 🙂 we probably don't want to expose sentry_path at this point, unfortunately...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Android, the NDK layer writes crash/native envelopes through a custom transport (
send_envelopeinndk/lib/src/main/jni/sentry.c) that targets the head SDK's outbox path. However:sentry_initonly creates its own database directory, which the JNI layer derives as.sentry-native— a sibling of the outbox, not the outbox itself (sentry.c:417-429).sentry_envelope_write_to_file, which ultimatelyopen(..., O_CREAT)s the file but does not create parent directories.So if the outbox directory does not exist when an envelope is flushed, the write fails silently (only a
SENTRY_WARN) and the crash report is lost. Today this works only because head SDKs (and the sample'sMainActivity.setupOutboxFolder()) create the outbox eagerly.This becomes a real risk as head SDKs move to lazy outbox/cache creation (e.g. getsentry/sentry-java#5792): a native envelope written before the head SDK's lazy creator runs would be dropped.
Change
Create the outbox directory in the transport before each write, using
sentry__path_create_dir_all— the same recursive, self-healing pattern every other sentry-native write path (cache, external) already uses. This makes native self-sufficient and lets head SDKs defer outbox creation without dropping native crash envelopes.Notes
sentry__path_*symbols are exported via thesentry_*glob insrc/exports.mapand are already reached from this JNI file viaextern(e.g.sentry__value_from_json,sentry__backend_preload), so this follows the established pattern.🤖 Generated with Claude Code