#Sentry with CodePush on React Native

2 messages · Page 1 of 1 (latest)

grave fossil
#

Hello guys, I am using Sentry on React Native, recently I am trying to configure Sentry correctly with CodePush so it shows the error stack correctly on the dashboard. Now I face a new issue which is calling Sentry.wrap before Sentry.init because I am waiting for the CodePush data to be available. Also note that Hermes is enabled.

Any recommendations on how to fix this?

import "@/helpers/IgnoreWarnings";
import { StyleSheet } from "react-native";
import React, { useRef } from "react";
import "react-native-gesture-handler";
import AppNavigation from "@/navigations/AppNavigation";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { NavigationContainer } from '@react-navigation/native';
import { withIAPContext } from "react-native-iap";
import codePush from "react-native-code-push";
import * as Sentry from '@sentry/react-native';
import Config from 'react-native-config';

const routingInstrumentation = new Sentry.ReactNavigationInstrumentation();
const sentrySampleRate = __DEV__ ? 0 : 0.25;
const enableTrace = __DEV__ ? false : true;
const enabled = __DEV__ ? false : true;

const sentryConfig: Sentry.ReactNativeOptions = {
  enabled,
  dsn: Config.SENTRY_DSN,
  enableTracing: enableTrace,
  tracesSampleRate: sentrySampleRate,
  integrations: [
    new Sentry.ReactNativeTracing({
      routingInstrumentation,
    }),
  ],
  _experiments: {
    profilesSampleRate: sentrySampleRate,
  },
};

codePush.getUpdateMetadata().then((update) => {
  if (update) {
    Sentry.init({
      ...sentryConfig,
      release: `${update.appVersion}+codepush:${update.label}`,
      dist: update.label,
    });
  } else {
    Sentry.init({
      ...sentryConfig,
    });
  }
});

let App = () => {
  const navigation = useRef<any>();

  return (
    <GestureHandlerRootView style={styles.main}>
      <NavigationContainer
        ref={navigation}
        onReady={() => {
          routingInstrumentation.registerNavigationContainer(navigation);
        }}>
        <AppNavigation />
      </NavigationContainer>
    </GestureHandlerRootView>
  );
};

codePush.sync(
  {},
  () => { },
  () => { },
  () => { },
).catch(console.error);

export default codePush(Sentry.wrap(withIAPContext(App)));

const styles = StyleSheet.create({
  main: {
    flex: 1,
  },
});
grave fossil
#

Also I have another issue with sourcemap, no debug id is attached to the artifact, I am using the following bash script to upload the sourcemap files

#!/bin/bash

# Check if all required arguments are provided
if [ "$#" -ne 5 ]; then
    echo "Usage: $0 <app_name> <target_version> <mandatory_update> <deployment_env> <platform>"
    exit 1
fi

# Set variables from arguments
APP_NAME=$1
TARGET_VERSION=$2
MANDATORY_UPDATE=$3
DEPLOYMENT_ENV=$4
PLATFORM=$5
HERMES_ENABLED="--use-hermes"
BUNDLE_OUTPUT_DIR="./build/$PLATFORM"

# Load Sentry properties based on the platform
SENTRY_PROPERTIES_FILE="./${PLATFORM}/sentry.properties"

if [ ! -f "$SENTRY_PROPERTIES_FILE" ]; then
    echo "Error: Sentry properties file not found at $SENTRY_PROPERTIES_FILE"
    exit 1
fi

export SENTRY_PROPERTIES=$SENTRY_PROPERTIES_FILE

# Generate the CodePush bundle
echo "Generating CodePush bundle for app $APP_NAME on platform $PLATFORM with target version $TARGET_VERSION..."
appcenter codepush release-react -a $APP_NAME -d $DEPLOYMENT_ENV -t $TARGET_VERSION $HERMES_ENABLED -m $MANDATORY_UPDATE --sourcemap-output-dir $BUNDLE_OUTPUT_DIR --output-dir $BUNDLE_OUTPUT_DIR 

# Check if the bundle generation was successful
if [ $? -ne 0 ]; then
  echo "Error: CodePush bundle generation failed."
  exit 1
fi

# Get the label of the latest release
LABEL=$(appcenter codepush deployment history $DEPLOYMENT_ENV -a $APP_NAME --output json | jq '.[-1][0]' -r)

# Upload the bundle and source maps to Sentry using sentry-cli
echo "Uploading bundle and source maps to Sentry using $SENTRY_PROPERTIES_FILE..."
sentry-cli react-native appcenter $APP_NAME $PLATFORM $BUNDLE_OUTPUT_DIR $BUNDLE_OUTPUT_DIR/CodePush --deployment $DEPLOYMENT_ENV --dist $LABEL

# Check if the upload was successful
if [ $? -ne 0 ]; then
  echo "Error: Uploading bundle and source maps to Sentry failed."
  exit 1
fi

echo "Release successful."