expo / sentry-expo

MIT License
202 stars 83 forks source link

How to attach screenshots on 'sentry-expo' package? #384

Closed AbisheekKumar closed 3 months ago

AbisheekKumar commented 6 months ago

Hi, I'm using 'sentry-expo' package as I have SDK 49. I can able to log the errors into sentry on following the expo's documentation. But the screenshots are not getting attached even though on enabling attachScreenshot:true in App.js I have used Sentry.Native.captureException() in ApiCall.js file like this.

App.js

import * as Sentry from 'sentry-expo';
Sentry.init({
  dsn: SENTRY_DSN,
  enableInExpoDevelopment: true,
  debug: true, 
  attachScreenshot:true,
  attachStacktrace:true,
  enableNative: true,
});

const App = () =>{
-------- rest of the code
}
export default App;

ApiCall.js:

import axios from 'axios';
import * as Sentry from 'sentry-expo';

export const TestApiCall = async (values, apiName) => {
    try {
        const response = await axios.post("http://127.0.0.1:8000/auth/testendpoint", values);
        return response.data;
    }
    catch (error) {
        const responseData = error.response ? error.response.data : error.message;
        const keys = Object.keys(responseData);
        if (keys.length > 0 && keys.length < 3) {
            const key = keys[0];
            const value = responseData[key];
            const errorMessage = value;
            Sentry.Native.captureException(errorMessage);
            throw new Error(errorMessage);
        }
        else {
            throw new Error('An error occured');
        }

    }
};

How to attach screenshots ?

krystofwoldrich commented 6 months ago

Hi @AbisheekKumar, thank you for the message, the screenshot will only be attached in Release builds could that be it?

In Expo Go the screenshots are not captured.

Note: @sentry/react-native now supports Expo out of the box!

Update to https://github.com/getsentry/sentry-react-native/releases/tag/5.16.0 or newer to get all the new features.

Migration guides available:

AbisheekKumar commented 6 months ago

Hi @krystofwoldrich Thank you, definitely I'll try it with the build. Sentry is extremely useful in case of error logging and gives all the info required for debugging.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.