-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync Java to C #937
sync Java to C #937
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet this is only the beginning and you will add a lot more hooks?
sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
Outdated
Show resolved
Hide resolved
sentry-samples/sentry-samples-android/src/main/java/io/sentry/sample/MainActivity.java
Outdated
Show resolved
Hide resolved
...amples/sentry-samples-servlet/src/main/java/io/sentry/samples/servlet/SentryInitializer.java
Outdated
Show resolved
Hide resolved
|
||
import io.sentry.protocol.User; | ||
|
||
public interface IScopeObserver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M: we'd need to implement the other fields too, like extra
, fingerprint
... and also to remove them, like removeTag
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The customer only asked about user,tag and breadcrumbs but yeah, for completion we'd have to add a bunch more stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or to document pretty well what we sync and what we don't, I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be an option. Specially if it'll require lots of JNI calls to sync stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags start with the min. necessary to unblock folks and see how it goes, we can implement the others later then.
starting with tags, extras, user, and breadcrumbs.
sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
Outdated
Show resolved
Hide resolved
…eObserver.java Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
Co-authored-by: Arpad Borsos <arpad.borsos@sentry.io>
...amples/sentry-samples-servlet/src/main/java/io/sentry/samples/servlet/SentryInitializer.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// TODO: make this a method | ||
if (data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Swatinem do you know an easier way to do this? from Map<String, Object> on java to sentry-native?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, I have no idea. But if you put this into a method, you can at least goto fail
and have a few finalizers (those DeleteLocalRef
) there. That should at least take care of the nesting.
Those jclass
/jmethodID
things can probably be done someplace else and cached inside a struct. I hope the pointers returned from there are stable across GC?
I can imagine something like:
struct {
jclass map;
jmethodID map_entrySet;
jclass set;
jmethodID set_iterator;
…
}
Also, why do you need entrySet
, can’t you get an iterator from Map
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the last question, no, https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet--
the suggestions above really make sense, I will experiment with just parsing the map as a String, let's see how it goes, last case I'd do this way, thanks
sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
Outdated
Show resolved
Hide resolved
} | ||
const char* valueStr = (*env)->GetStringUTFChars(env, value, NULL); | ||
if (!valueStr) { // Out of memory | ||
(*env)->ReleaseStringUTFChars(env, key, keyStr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never called this for any of the other cases. should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd not be a bad idea, but those values are set by us and quite small Strs length, here could be arbitrary data set by customers like a full JSON response, that's why it's so important, good catch.
} | ||
|
||
// TODO: make this a method | ||
if (data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn, I have no idea. But if you put this into a method, you can at least goto fail
and have a few finalizers (those DeleteLocalRef
) there. That should at least take care of the nesting.
Those jclass
/jmethodID
things can probably be done someplace else and cached inside a struct. I hope the pointers returned from there are stable across GC?
I can imagine something like:
struct {
jclass map;
jmethodID map_entrySet;
jclass set;
jmethodID set_iterator;
…
}
Also, why do you need entrySet
, can’t you get an iterator from Map
directly?
…ntry-java into feat/java-native-scope-sync
@@ -11,8 +11,257 @@ struct transport_options { | |||
|
|||
struct transport_options g_transport_options; | |||
|
|||
JNIEXPORT void JNICALL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to check NPEs here, because on Java the thread-safe list dont accept null keys and values
@@ -25,27 +274,35 @@ static void send_envelope(sentry_envelope_t *envelope, void *unused_data) { | |||
sentry_envelope_write_to_file(envelope, outbox_path); | |||
} | |||
|
|||
JNIEXPORT void JNICALL Java_io_sentry_android_ndk_SentryNdk_initSentryNative(JNIEnv *env, jclass cls, jobject sentry_sdk_options) { | |||
JNIEXPORT void JNICALL | |||
Java_io_sentry_android_ndk_SentryNdk_initSentryNative(JNIEnv *env, jclass cls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just indentation, ignore it
private final @NotNull List<IScopeObserver> observers = new ArrayList<>(); | ||
|
||
/** Enable the Java -> NDK Scope sync */ | ||
private boolean enableScopeSync; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opt-in by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #937 +/- ##
=======================================
Coverage ? 71.23%
Complexity ? 1245
=======================================
Files ? 126
Lines ? 4575
Branches ? 472
=======================================
Hits ? 3259
Misses ? 1067
Partials ? 249
Continue to review full report at Codecov.
|
// we create an object because the Java layer parses it as a Map | ||
sentry_value_t dataObject = sentry_value_new_object(); | ||
sentry_value_set_by_key(dataObject, "data", sentry_value_new_string(charData)); | ||
|
||
sentry_value_set_by_key(crumb, "data", dataObject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be improved if we expose something like sentry_value_from_json
cc @Swatinem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve myself!
Thanks for building this @marandaneto !!:rocket: |
*/ | ||
@Override | ||
public String serialize(final @NotNull Map<String, Object> data) throws Exception { | ||
Objects.requireNonNull(data, "The SentryEnvelope object is required."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the exception needs better wording :-D
if (data) { | ||
const char *charData = (*env)->GetStringUTFChars(env, data, 0); | ||
|
||
// we create an object because the Java layer parses it as a Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, was that there already? I don’t see it in this PR
PoC Java -> native scope sync
TODO:
So far:
Crumbs:

user:

Tags: