Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/sample-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
path: ${{ env.REACT_NATIVE_SAMPLE_PATH }}/ios/*.log

build-android:
name: Build ${{ matrix.rn-architecture }} android ${{ matrix.build-type }}
name: Build ${{ matrix.rn-architecture }} android ${{ matrix.build-type }} ${{ matrix.native-backend }}
runs-on: ubuntu-latest
needs: [diff_check, detect-changes]
if: >-
Expand All @@ -156,6 +156,7 @@ jobs:
matrix:
rn-architecture: ["new"]
build-type: ["dev", "production"]
native-backend: ["inproc", "native"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Expand Down Expand Up @@ -185,6 +186,8 @@ jobs:

- name: Build Android App
working-directory: ${{ env.REACT_NATIVE_SAMPLE_PATH }}
env:
SENTRY_NATIVE_BACKEND: ${{ matrix.native-backend }}
run: |
export RN_ARCHITECTURE="${{ matrix.rn-architecture }}"
[[ "${{ matrix.build-type }}" == "production" ]] && export CONFIG='release' || export CONFIG='debug'
Expand Down Expand Up @@ -227,15 +230,15 @@ jobs:
if: ${{ matrix.rn-architecture == 'new' && matrix.build-type == 'production' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: sample-rn-${{ matrix.rn-architecture }}-${{ matrix.build-type }}-android
name: sample-rn-${{ matrix.rn-architecture }}-${{ matrix.build-type }}-${{ matrix.native-backend }}-android
path: ${{ env.ANDROID_APP_ARCHIVE_PATH }}
retention-days: 1

- name: Upload logs
if: ${{ always() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: build-sample-${{ matrix.rn-architecture }}-android-${{ matrix.build-type }}-no-frameworks-logs
name: build-sample-${{ matrix.rn-architecture }}-android-${{ matrix.build-type }}-${{ matrix.native-backend }}-no-frameworks-logs
path: ${{ env.REACT_NATIVE_SAMPLE_PATH }}/android/*.log

build-macos:
Expand Down Expand Up @@ -666,7 +669,7 @@ jobs:
run: yarn test-ios

test-android:
name: Test android production REV2
name: Test android production ${{ matrix.native-backend }} REV2
runs-on: ubuntu-latest
needs: [diff_check, detect-changes, build-android]
if: >-
Expand All @@ -675,6 +678,14 @@ jobs:
&& needs.detect-changes.outputs.needs_sample_react_native == 'true'
&& (needs.detect-changes.outputs.sample_react_native == 'true' || needs.detect-changes.outputs.needs_android == 'true')
}}
strategy:
fail-fast: false
matrix:
include:
- native-backend: "inproc"
test-script: "test-android"
- native-backend: "native"
test-script: "test-android-native"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Expand All @@ -686,7 +697,7 @@ jobs:
- name: Download Android APK
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: sample-rn-new-production-android
name: sample-rn-new-production-${{ matrix.native-backend }}-android
path: ${{ env.REACT_NATIVE_SAMPLE_PATH }}

- name: Unzip Android APK
Expand Down Expand Up @@ -740,4 +751,4 @@ jobs:
-camera-front none
-timezone US/Pacific
working-directory: ${{ env.REACT_NATIVE_SAMPLE_PATH }}
script: yarn test-android
script: yarn ${{ matrix.test-script }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
> make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first.
<!-- prettier-ignore-end -->

## Unreleased

### Features

- Add experimental, opt-in out-of-process crash reporting on Android ([#7152](https://github.com/getsentry/sentry-react-native/pull/7152))
- To enable it, set `SENTRY_NATIVE_BACKEND=native` in `android/gradle.properties` or in the build environment. A crash service then sends native crashes at crash time, instead of on the next launch.

## 8.37.0

### Features
Expand Down
12 changes: 11 additions & 1 deletion packages/core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,21 @@ android {
}

def sentryAndroidVersion = '8.66.0'
def sentryNativeBackend = project.findProperty('SENTRY_NATIVE_BACKEND')
?: providers.environmentVariable('SENTRY_NATIVE_BACKEND').getOrNull()

dependencies {
compileOnly files('libs/replay-stubs.jar')
implementation 'com.facebook.react:react-native:+'
api "io.sentry:sentry-android:$sentryAndroidVersion"
if (sentryNativeBackend == 'native') {
// Both backends provide `libsentry.so`, so the out-of-process one replaces the inproc one.
api("io.sentry:sentry-android:$sentryAndroidVersion") {
exclude group: 'io.sentry', module: 'sentry-native-ndk'
}
api "io.sentry:sentry-android-ndk-outproc:$sentryAndroidVersion"
} else {
api "io.sentry:sentry-android:$sentryAndroidVersion"
}
debugImplementation "io.sentry:sentry-spotlight:$sentryAndroidVersion"

testImplementation 'junit:junit:4.13.2'
Expand Down
8 changes: 8 additions & 0 deletions samples/react-native/e2e/jest.config.android.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const baseConfig = require('./jest.config.base');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
globals: { E2E_PLATFORM: 'android' },
testMatch: ['<rootDir>/e2e/**/*.test.android.native.ts'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, it, beforeAll, expect, afterAll } from '@jest/globals';
import { Envelope, EventItem } from '@sentry/core';

import {
createSentryServer,
containingEventWithExceptionType,
} from '../../utils/mockedSentryServer';
import { getItemOfTypeFrom } from '../../utils/event';
import { maestro } from '../../utils/maestro';

describe('Capture native crash at crash time (Android native backend)', () => {
let sentryServer = createSentryServer();

let envelope: Envelope;

beforeAll(async () => {
await sentryServer.start();

const envelopePromise = sentryServer.waitForEnvelope(
containingEventWithExceptionType('SIGSEGV'),
);

// The flow never relaunches the app, so only the crash service can send
// the crash.
await maestro(
'tests/captureNativeCrash/captureNativeCrash.test.android.native.yml',
);

envelope = await envelopePromise;
}, 240000); // 240 seconds timeout

afterAll(async () => {
await sentryServer.close();
});

it('envelope contains fatal native crash event', async () => {
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');

expect(item).toEqual([
expect.objectContaining({
type: 'event',
}),
expect.objectContaining({
level: 'fatal',
platform: 'native',
sdk: expect.objectContaining({
name: 'sentry.native.android.react-native',
}),
exception: {
values: [
expect.objectContaining({
type: 'SIGSEGV',
mechanism: expect.objectContaining({
type: 'signalhandler',
handled: false,
}),
}),
],
},
}),
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: io.sentry.reactnative.sample
---
- launchApp:
clearState: true
stopApp: true

# App launches on ErrorsTab (first tab)
# Wait a moment for the screen to fully load
- waitForAnimationToEnd:
timeout: 2000

- scrollUntilVisible:
element: "Crash in Android Cpp"
timeout: 10000
direction: DOWN
- tapOn: "Crash in Android Cpp"

# Don't relaunch: the crash service must send the crash on its own
- extendedWaitUntil:
notVisible: "Crash in Android Cpp"
timeout: 15000
21 changes: 17 additions & 4 deletions samples/react-native/e2e/utils/mockedSentryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ export function createSentryServer({ port = 8961 } = {}): {
const server = createServer((req: IncomingMessage, res: ServerResponse) => {
let body: Buffer = Buffer.from([]);

const gunzip = createGunzip();
req.pipe(gunzip);
// The native crash daemon sends uncompressed envelopes.
const stream =
req.headers['content-encoding'] === 'gzip'
? req.pipe(createGunzip())
: req;

gunzip.on('data', (chunk: Buffer) => {
stream.on('data', (chunk: Buffer) => {
body = Buffer.concat([body, chunk]);
});

gunzip.on('end', () => {
stream.on('end', () => {
const request = {
path: req.url,
headers: req.headers,
Expand Down Expand Up @@ -133,6 +136,16 @@ export function containingEventWithMessage(message: string) {
);
}

export function containingEventWithExceptionType(type: string) {
return (envelope: Envelope) =>
envelope[1].some(
item =>
itemHeaderIsType(item[0], 'event') &&
itemBodyIsEvent(item[1]) &&
!!item[1].exception?.values?.some(value => value.type === type),
);
}

export function containingTransaction(envelope: Envelope) {
return envelope[1].some(item => itemHeaderIsType(item[0], 'transaction'));
}
Expand Down
1 change: 1 addition & 0 deletions samples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"set-test-dsn-ios": "scripts/set-dsn-ios.mjs",
"test-android-manual": "scripts/test-android-manual.sh",
"test-android-auto": "scripts/test-android-auto.sh",
"test-android-native": "scripts/test-android-native.sh",
"test-ios-manual": "scripts/test-ios-manual.sh",
"test-ios-auto": "scripts/test-ios-auto.sh",
"lint": "npx oxlint",
Expand Down
27 changes: 27 additions & 0 deletions samples/react-native/scripts/test-android-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e # exit on error

# Get current directory
thisFileDirPath=$(dirname "$0")
reactProjectRootPath="$(cd "$thisFileDirPath/.." && pwd)"

maybeApkPath=$(find "${reactProjectRootPath}" -maxdepth 1 -name "*.apk")

# Check if any APK files exist
apk_count=$(echo "$maybeApkPath" | wc -l)

if [ -n "$maybeApkPath" ] && [ $apk_count -eq 1 ]; then
# Force install single APK using adb
apk_file="${maybeApkPath}"
echo "Installing $apk_file..."
adb install -r "$apk_file"
elif [ $apk_count -gt 1 ]; then
echo "Error: Multiple APK files found. Expected only one APK file."
exit 1
else
echo "No APK files found, continuing without install"
fi

# Run the tests
npx jest --config e2e/jest.config.android.native.js
Loading