Sentry-javascript: [REACT-NATIVE] Send device information like model and OS version

Created on 4 Mar 2017  路  4Comments  路  Source: getsentry/sentry-javascript

I was expecting to have the device details on the crash reports, but that didn't happen.

Is this going to be supported? Any way we can do that today?

image

Most helpful comment

@orlando thanks for your insight!

I was able to fully implement it without a fork, here is my solution:

Code

import DeviceInfo from 'react-native-device-info'
import Raven from 'raven-js'
import RavenNative from 'raven-js/plugins/react-native'

import pkg from '../package.json'

RavenNative(Raven)

if (!__DEV__) {
  Raven
    .config('https://[email protected]/...', {
      release: pkg.version,
      dataCallback: data => {
        data.contexts = data.contexts || {}

        data.contexts.device = Object.assign(data.contexts.device || {}, {
          name: DeviceInfo.getDeviceName(),
          family: DeviceInfo.getBrand(),
          model: DeviceInfo.getModel(),
        })

        data.contexts.os = Object.assign(data.contexts.os || {}, {
          name: DeviceInfo.getSystemName(),
          version: DeviceInfo.getSystemVersion(),
        })

        return data
      },
    })
    .install()
}

Result

image

image

All 4 comments

There are libs that get this information, like https://github.com/rebeccahughes/react-native-device-info, but I see #809 wasn't merged, so I'm not sure we can set this somehow. cc @orlando

@brunolemos I ended up using my fork https://github.com/orlando/raven-js. You only need device information from JavaScript, in Java you should use the raven-java library

@orlando thanks for your insight!

I was able to fully implement it without a fork, here is my solution:

Code

import DeviceInfo from 'react-native-device-info'
import Raven from 'raven-js'
import RavenNative from 'raven-js/plugins/react-native'

import pkg from '../package.json'

RavenNative(Raven)

if (!__DEV__) {
  Raven
    .config('https://[email protected]/...', {
      release: pkg.version,
      dataCallback: data => {
        data.contexts = data.contexts || {}

        data.contexts.device = Object.assign(data.contexts.device || {}, {
          name: DeviceInfo.getDeviceName(),
          family: DeviceInfo.getBrand(),
          model: DeviceInfo.getModel(),
        })

        data.contexts.os = Object.assign(data.contexts.os || {}, {
          name: DeviceInfo.getSystemName(),
          version: DeviceInfo.getSystemVersion(),
        })

        return data
      },
    })
    .install()
}

Result

image

image

All right, sentry just released a more complete React Native integration!
It will now send device details and catch native crashes.

https://blog.sentry.io/2017/03/14/react-native
https://docs.sentry.io/clients/react-native/

EDIT: iOS only by now 馃槖 So the code above is still useful.

Was this page helpful?
0 / 5 - 0 ratings