Skip to content

Commit

Permalink
fix: Envelope header bytes length (#773)
Browse files Browse the repository at this point in the history
* fix: Envelope header bytes length

* "compile"

* fix: Bump to stable and fix code

* ref: Remove logs

Co-authored-by: Daniel Griesser <[email protected]>
  • Loading branch information
bruno-garcia and HazAT authored Feb 21, 2020
1 parent 4edcdac commit fdb1753
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
10 changes: 10 additions & 0 deletions android/src/main/java/io/sentry/RNSentryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ export const NATIVE = {
* Sending the event over the bridge to native
* @param event Event
*/
sendEvent(event: Event): PromiseLike<Response> {
async sendEvent(event: Event): Promise<Response> {
if (NATIVE.platform === "android") {
const header = JSON.stringify({ event_id: event.event_id });

(event as any).message = {
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}`;
Expand Down

0 comments on commit fdb1753

Please sign in to comment.