diff --git a/android/build.gradle b/android/build.gradle index a46a34cfac..1cd86adfc3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -34,5 +34,5 @@ android { dependencies { implementation 'com.facebook.react:react-native:+' - implementation 'io.sentry:sentry-android:2.0.0-rc04' + implementation 'io.sentry:sentry-android:2.0.0' } diff --git a/android/src/main/java/io/sentry/RNSentryModule.java b/android/src/main/java/io/sentry/RNSentryModule.java index 5e5be51026..9b7f428f4e 100644 --- a/android/src/main/java/io/sentry/RNSentryModule.java +++ b/android/src/main/java/io/sentry/RNSentryModule.java @@ -15,6 +15,7 @@ import java.io.File; import java.io.FileOutputStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Iterator; @@ -146,6 +147,15 @@ public void captureEnvelope(String envelope, Promise promise) { promise.resolve(true); } + @ReactMethod + public void getStringBytesLength(String payload, Promise promise) { + try { + promise.resolve(payload.getBytes("UTF-8").length); + } catch (UnsupportedEncodingException e) { + promise.reject(e); + } + } + private static PackageInfo getPackageInfo(Context ctx) { try { return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0); diff --git a/src/js/wrapper.ts b/src/js/wrapper.ts index b65a432ccf..8f6dbd8003 100644 --- a/src/js/wrapper.ts +++ b/src/js/wrapper.ts @@ -11,7 +11,7 @@ export const NATIVE = { * Sending the event over the bridge to native * @param event Event */ - sendEvent(event: Event): PromiseLike { + async sendEvent(event: Event): Promise { if (NATIVE.platform === "android") { const header = JSON.stringify({ event_id: event.event_id }); @@ -19,9 +19,16 @@ export const NATIVE = { message: event.message }; const payload = JSON.stringify(event); + let length = payload.length; + try { + // tslint:disable-next-line: no-unsafe-any + length = await RNSentry.getStringBytesLength(payload); + } catch { + // The native call failed, we do nothing, we have payload.length as a fallback + } const item = JSON.stringify({ content_type: "application/json", - length: payload.length, + length, type: "event" }); const envelope = `${header}\n${item}\n${payload}`;