exceptionless / Exceptionless.JavaScript

Exceptionless JavaScript client
http://exceptionless.com
Apache License 2.0
59 stars 24 forks source link

this package couldn't work on React Native app #89

Closed choby closed 1 year ago

choby commented 3 years ago

I installed this package on the React Native app as documented like this : https://github.com/erikras/react-redux-universal-hot-example/compare/master...niemyjski:master, but on ios/android devices it couldn't work, exceptionlessClient is null, and I tried import * as Exceptionless, couldn't work too.

this is my repo :

https://github.com/choby/exceptionless_test/tree/master

please run it use ios/android devices

niemyjski commented 3 years ago

Thanks for logging this, this definitely feels like a bug. I wonder if we need to put in some kind of webpack config to tell it what not to exclude / tree shake. I'll need to setup an emulator and look at this unless someone can tackle this (would be a massive help).

niemyjski commented 3 years ago

Just a status update, we just spent a lot of time getting onto the latest eslint & typescript. We just fixed some bugs and made it possible for us to run and debug tests from within vs code. While doing so, we are thinking we may need to invest into learna and have different build artifacts that tooling can look at and tree shake and do the right thing. I'm thinking what could be going on here is webpack needs to be configured with some settings as it can't figure out our dependencies and do the right thing currently.

niemyjski commented 3 years ago

Also, Do you give us permission and rights to add your sample to this repo as a sample? Or could you submit a pr with it to the samples folder. Sorry for taking so long to get this resolved.

choby commented 3 years ago

yes,you can add my sample to this repo, thank you for solving this problem 👍👍👍

niemyjski commented 3 years ago

I did some deep diving into your repo and seen if it was possible to tackle this in the current client version. I got it working with some tweaks to the umd, but then our submission clients which use an old style of xhr were completely broken, we'd need to upgrade the implementation. I'm going to put this work item off for the 2.0 release. We just cut 1.6.4 release which will be our last 1.x release and we are going to rework the client a bit to make it more idiomatic and make sure it works also with react native out of the box!

polluterofminds commented 3 years ago

@choby it doesn't make use of the exceptionless client, but it might be helpful if you want a slightly more manual workaround, this is what I did in my RN app:

export const logError = async (error) => {  
  try {
    const config = {
      headers: {
        'Authorization': `Bearer ${EXCEPTIONLESS_API_KEY}`, 
        'Content-Type': 'application/json'
      }
    }
    const data = { 
      "type": "error", 
      "date":new Date().toISOString(), 
      "@simple_error": 
        { "message": error.message ? error.message : "Unknown Error", 
        "type": "System.Exception", 
        "stack_trace": JSON.stringify(error) 
      }
    }

    await axios.post('https://collector.exceptionless.io/api/v2/events', JSON.stringify(data), config);
  } catch (error) {
    console.log(error);
  }
}

My use case was really simplified though. I only wanted to log exceptions, but you could extend this to log other stuff as well.

niemyjski commented 3 years ago

Here is how another customer was using it but running into issues:

import React from 'react';
import { Provider } from 'react-redux';
import ErrorBoundary from 'react-native-error-boundary';
import { ExceptionlessClient } from 'exceptionless';
import RootContainer from './src/Containers/RootContainer';
import createStore from './src/Redux';

const exceptionLessClient = new ExceptionlessClient().default;
exceptionLessClient.config.apiKey = 'EXCEPTIONLESS_API_KEY';
const errorHandler = (error) => {
 exceptionLessClient.submitException(error);
};

export const store = createStore();
const App = () => (
 <Provider store={store}>
 <ErrorBoundary onError={errorHandler}>
 <RootContainer />
 </ErrorBoundary>
 </Provider>
);

export default App;
niemyjski commented 3 years ago

We just merged in our 2.0 rewrite and I'll be updating the readme and then cutting a release. Is there any chance you could try out the 2.0.0-beta when we tag it.

niemyjski commented 1 year ago

We did a massive amount of work in 2.0 and this should be working now. Can you please check it out and let us know what you find.