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

Can't access Sentry methods like captureException or captureMessage #183

Closed
wunnle opened this issue Apr 8, 2021 · 11 comments
Closed

Can't access Sentry methods like captureException or captureMessage #183

wunnle opened this issue Apr 8, 2021 · 11 comments

Comments

@wunnle
Copy link

wunnle commented Apr 8, 2021

Summary

Sentry imported from 'sentry-expo' doesn't allow access to Sentry methods

Screen Shot 2021-04-08 at 5 06 24 PM

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

No response

Environment

Expo CLI 4.0.17 environment info:
System:
OS: macOS 11.1
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.3 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.9 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
npmPackages:
expo: ^39.0.0 => 39.0.5
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz => 0.63.2
react-native-web: ~0.13.7 => 0.13.18
Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

import * as Sentry from 'sentry-expo'
import React, { useEffect } from 'react'

const Comp = () => {
useEffect(() => {
Sentry.captureMessage('123')
}, [])
}

@RRaideRR
Copy link

RRaideRR commented Apr 9, 2021

took me also a while to figure that out...

use: Sentry.Native.captureMessage('123')

I think this should be part of the documentation.

@cruzach
Copy link
Contributor

cruzach commented Apr 9, 2021

It is part of the documentation: https://docs.expo.io/guides/using-sentry/#install-and-configure-sentry & https://github.com/expo/sentry-expo/blob/master/CHANGELOG.md#-breaking-changes

@superyarik
Copy link

@cruzach it's not clear now how to get docs for sentry in sentry-expo:
in changelog i see "upgraded to @sentry/react-native 1.7.1 ", but on sentry docs page:
"Package: npm:@sentry/react-native Version: 2.4.1"

and there is no version select, like in expo docs

@cruzach
Copy link
Contributor

cruzach commented Apr 26, 2021

Sentry works the same in sentry-expo, @sentry/react-native is exposed via Sentry.Native so you can just reference Sentry's docs for sentry-specific functions

Closing this since it is documented

@cruzach cruzach closed this as completed Apr 26, 2021
@slorber
Copy link
Contributor

slorber commented Jun 25, 2021

@cruzach it's not 100% clear to me how to make this work.

Previously there were no Native + Browser, and it used to work without additional steps in managed + ExpoKit.

Now if I want to test this in managed, it does not seem to work with either:

  • Native: Error: SentryError: Native Client is not available, can't start on native.
  • Browser: backend.js:32 Sentry Logger [Warn]: Session tracking in non-browser environment with @sentry/browser is not supported.
    With any of those I can't see the error on Sentry (using enableInExpoDevelopment + Expo Go)

Now, I understand that for EAS build you need to add the plugin, and for bare workflow you need to follow additional instructions.

Was wondering how to first make it work in dev + Expo Go, as I want to keep using it despite being ejected to Bare

The doc does not explain very clearly when to use Native vs Browser?

Am I supposed to switch implementation according to the context? (bare vs Expo Go)

Note: the github readme still says import * as Sentry from 'sentry-expo'; which does not look correct anymore

@cruzach
Copy link
Contributor

cruzach commented Jun 25, 2021

Use Native in your native environments (iOS and Android apps), and Browser on web

import * as Sentry from 'sentry-expo' is correct

I've tested this in managed workflow just yesterday for the new release, and confirmed it worked as expected. for example, to capture an error when running on Android or iOS, you would call Sentry.Native.CaptureException(...)

@slorber
Copy link
Contributor

slorber commented Jun 25, 2021

* as Sentry is indeed correct IF you use Sentry.Native.init() which is not what your snippet shows:

import * as Sentry from 'sentry-expo';

// Use Sentry.Native.init() instead ?
Sentry.init({
  dsn: 'YOUR DSN HERE',
  enableInExpoDevelopment: true,
  debug: true, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
});

Now what you say is that even in Expo Go I should use Sentry.Native right?

Actually this is what I get when running this code in Expo Go, SDK 41:

import React from 'react';
import { View } from 'react-native';

// import { Browser as Sentry } from 'sentry-expo';
import { Native as Sentry } from 'sentry-expo';

Sentry.init({
  dsn: 'https://sdgdgfdg@sentry.io/sdfds',
  enableInExpoDevelopment: true,
  debug: true,
});

Sentry.captureException(new Error('oops test seb'));

export default function App() {
  return <View />;
}

image

(it didn't work much better when using Browser, but only emit a warning)

@cruzach
Copy link
Contributor

cruzach commented Jun 25, 2021

@slorber We export the init method directly, so there's no need to call Sentry.Native.init. You can refer to the docs for appropriate usage, or take a look at the source code where we export the init method.

// import { Browser as Sentry } from 'sentry-expo';
import { Native as Sentry } from 'sentry-expo';

This isn't the recommended way to import, so I really recommend you follow the docs, it'll help avoid issues like this. This is what we document:

import * as Sentry from 'sentry-expo';

Sentry.init({
  dsn: 'YOUR DSN HERE',
  enableInExpoDevelopment: true,
  debug: true, // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production.
});

// Access any @sentry/react-native exports via:
Sentry.Native.*

// Access any @sentry/browser exports via:
Sentry.Browser.*

@slorber
Copy link
Contributor

slorber commented Jun 25, 2021

I see, didn't understand that the init was exposed directly and that it performs additional logic compared to Sentry.Native.init

Now using something that looks correct, but it's still not working in Expo Go 🤪

import React, { useEffect } from 'react';
import { View } from 'react-native';

import * as Sentry from 'sentry-expo';

Sentry.init({
  dsn:
    'https://c7d20b032ab74258bef7baf9f2bd806f@o91835.ingest.sentry.io/5834150',
  enableInExpoDevelopment: true,
  debug: true,
});

export default function App() {
  useEffect(() => {
    Sentry.Native.captureException(new Error('oops test'));
    console.log("sentry error reported");
  }, []);

  return <View style={{flex: 1, backgroundColor: "red"}}/>;
}

(new test project, the DSN is not sensitive)

image

image

No console error this time, but no error reported either

@cruzach
Copy link
Contributor

cruzach commented Jun 25, 2021

Screen Shot 2021-06-25 at 12 12 01 PM
same exact code works for me, i would make sure you're looking at the correct dashboard, or make sure you're using the correct sentry-expo version SDK 41 means ^3.1.0, SDK 42 means ^4.0.0. Barring all that, the next step would be to talk to Sentry

@slorber
Copy link
Contributor

slorber commented Jun 25, 2021

oh, I understand now 😓

Your organization has depleted its error capacity for the current usage period. Upgrade to avoid data loss.

We just reached the free plans limit and all the errors I try to send are now dropped. Unfortunately nothing tells me this apart the billing page... Sorry for losing your time... Creating a new org with an empty fresh quota definitively works as intended

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

5 participants