@@ -202,23 +202,54 @@ - (void)setReleaseVersionDist:(SentryEvent *)event {
202202 if (NSClassFromString (@" RCTBatchedBridge" )) {
203203 [self swizzleCallNativeModule: NSClassFromString (@" RCTBatchedBridge" )];
204204 } else {
205- // TODO fix stacktrace merging
206- reject (@" SentryException" , @" stacktrace merging not supported" , nil );
207- return ;
205+ [self swizzleInvokeWithBridge: NSClassFromString (@" RCTModuleMethod" )];
208206 }
209207 resolve (@YES );
210208}
211209
212- - (void )swizzleCallNativeModule : (Class )class {
210+ - (void )swizzleInvokeWithBridge : (Class )class {
213211 static const void *key = &key;
214- SEL selector = @selector (callNativeModule:method:params : );
212+ SEL selector = @selector (invokeWithBridge:module:arguments : );
215213 uintptr_t callNativeModuleAddress = [class instanceMethodForSelector: selector];
216214
217215 SentrySwizzleInstanceMethod (class,
218216 selector,
219217 SentrySWReturnType (id ),
218+ SentrySWArguments (RCTBridge *bridge, id module, NSArray *arguments),
219+ SentrySWReplacement ({
220+ // TODO: refactor this block, its used twice
221+ NSMutableArray *newParams = [NSMutableArray array ];
222+ if (arguments != nil && arguments.count > 0 ) {
223+ for (id param in arguments) {
224+ if ([param isKindOfClass: NSDictionary .class] && param[@" __sentry_stack" ]) {
225+ @synchronized (SentryClient.sharedClient ) {
226+ NSMutableDictionary *prevExtra = SentryClient.sharedClient .extra .mutableCopy ;
227+ [prevExtra setValue: [NSNumber numberWithUnsignedInteger: callNativeModuleAddress] forKey: @" __sentry_address" ];
228+ [prevExtra setValue: SentryParseJavaScriptStacktrace ([RCTConvert NSString: param[@" __sentry_stack" ]]) forKey: @" __sentry_stack" ];
229+ SentryClient.sharedClient .extra = prevExtra;
230+ }
231+ } else {
232+ if (param != nil ) {
233+ [newParams addObject: param];
234+ }
235+ }
236+ }
237+ }
238+ return SentrySWCallOriginal (bridge, module, newParams);
239+ }), SentrySwizzleModeOncePerClassAndSuperclasses, key);
240+ }
241+
242+ - (void )swizzleCallNativeModule : (Class )class {
243+ static const void *key = &key;
244+ SEL selctor = @selector (callNativeModule:method:params: );
245+ uintptr_t callNativeModuleAddress = [class instanceMethodForSelector: selctor];
246+
247+ SentrySwizzleInstanceMethod (class,
248+ selctor,
249+ SentrySWReturnType (id ),
220250 SentrySWArguments (NSUInteger moduleID, NSUInteger methodID, NSArray *params),
221251 SentrySWReplacement ({
252+ // TODO: refactor this block, its used twice
222253 NSMutableArray *newParams = [NSMutableArray array ];
223254 if (params != nil && params.count > 0 ) {
224255 for (id param in params) {
0 commit comments