Skip to content
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

Using Sentry directly in native code #813

Closed
5 of 11 tasks
jacklj opened this issue Apr 3, 2020 · 4 comments
Closed
5 of 11 tasks

Using Sentry directly in native code #813

jacklj opened this issue Apr 3, 2020 · 4 comments

Comments

@jacklj
Copy link

jacklj commented Apr 3, 2020

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @sentry/react-native
  • react-native-sentry

SDK version: 1.3.3
react-native version: 0.60.5

Are you using Expo?

  • Yes
  • No

Are you using sentry.io or on-premise?

  • sentry.io (SaaS)
  • on-premise

I think it is possible to use Sentry directly from the native code in your react-native project, but this doesn't seem to be mentioned anywhere in the docs.

I'd like to be able to e.g. add breadcrumbs and capture exception, directly in Objective-C code.

I assume that when installing Sentry for react-native, it installs Sentry for Cocoa.

However, when I try and initialise Sentry in AppDelegate.m, with:

@import Sentry;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [SentrySDK initWithOptions:@{
        @"dsn": @"xxx",
        @"debug": @(YES)
    }];
    return YES;
}

Xcode says "Module 'Sentry' not found"

What is the correct way to use react-native Sentry directly from (iOS) native code?

Thanks

@tapz
Copy link

tapz commented May 18, 2020

I would also like to know how to use Sentry directly in Java code when integrated to the React Native SDK. Now I just get this:

MainActivity.java:69: error: cannot find symbol
import io.sentry.Sentry;

@brandons
Copy link

@jacklj @tapz Did either of you find a solution for this?

@tapz
Copy link

tapz commented Jul 30, 2020

In Android/Java, I had to change the import to import io.sentry.core.Sentry;

In iOS, I simpy do import Sentry and then SentrySDK.capture(event: sentryEvent).

The initialization with dsn is done in RN code by calling Sentry.init.

@jennmueng
Copy link
Member

jennmueng commented Jul 30, 2020

Hi everyone, I joined Sentry after this issue was made so I didn't see it until now, sorry!

Yes that is correct. On Android it is io.sentry.core.Sentry and on iOS it's either import Sentry or import <Sentry/Sentry.h>.

You do not call init from native code otherwise it might not work with the React Native SDK, although this does mean that any errors before the JS code calls init will not be caught, and calling any methods from the native SDK before calling init would not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants