Add method to control native tracing
Currently when set a tracesSampleRate or tracesSampler.
It's not sync into native during initNativeSdk.
However if I set autoInitializeNativeSdk to false. The frame data from RNSentryModule will be lost because of native sdk isn't initialized via RNSentryModule.
The only thing I can do for that is using patch-package to have a tracesSampleRate or tracesSampler to have both.
I'm not sure this is expected feature or unexpected bug. I leave it as feature request here.
Sorry for the delay on replying. We have disabled passing down these values from JS into Native because that would result in double-reporting transactions. And the transactions from Native are not necessarly actionable from your end if you're writing JS.
What are you trying to accomplish by setting this flag?
I can understand that tracesSampleRate/tracesSampler can not be transmit to native especially for tracesSampler.
However when I disable autoInitializeNativeSdk. I would assume I can still have frame tracing enabled. Which is the case for iOS but not for Android.
Here is my work around by use patch-package
in RNSentryModule:
public class RNSentryModule extends ReactContextBaseJavaModule {
//.. other methods
// same code from initNativeSdk
@ReactMethod
public void enablePerformance() {
if (androidXAvailable) {
frameMetricsAggregator = new FrameMetricsAggregator();
final Activity currentActivity = getCurrentActivity();
if (frameMetricsAggregator != null && currentActivity != null) {
try {
frameMetricsAggregator.add(currentActivity);
} catch (Throwable ignored) {
// throws ConcurrentModification when calling addOnFrameMetricsAvailableListener
// this is a best effort since we can't reproduce it
logger.warning("Error adding Activity to frameMetricsAggregator.");
}
}
} else {
logger.warning("androidx.core' isn't available as a dependency.");
}
}
//.. other methods
}
in my App.js:
Sentry.init({});
if (Platform.OS === "android") {
NativeModules.RNSentry.enablePerformance();
}
If you want to enable performance on the Native SDKs, you can do with https://docs.sentry.io/platforms/react-native/manual-setup/native-init/
Maybe we should init the frameMetricsAggregator variable even if autoInitializeNativeSdk is disabled, but enableAutoPerformanceTracking is enabled, agreed, otherwise it's more boilerplate for the final user.
@marandaneto Yeah but that would not add frame data into my JavaScript transaction. In order to have both tracesSampleRate on native and react-native. I need to disable JS auto init native SDK. Init native SDK myself. then use the alternative I provide about to enable frame rate data in react-native.
Maybe we should init the frameMetricsAggregator variable even if autoInitializeNativeSdk is disabled
That's exactly what I'm looking for. frameMetricsAggregator probably shouldn't be part of nativeInit.
Relates to https://github.com/getsentry/sentry-cocoa/issues/2262