DataDog / dd-sdk-reactnative

Datadog SDK for ReactNative
Apache License 2.0
122 stars 42 forks source link

Can @datadog/mobile-react-native be used without @datadog/datadog-ci ? #701

Closed ioeldev closed 3 months ago

ioeldev commented 3 months ago

Question

I would like to use Datadog Logs only (not interested in RUM) on our react-native app, and when building the app i got Error: Cannot find module '@datadog/datadog-ci/package.json' While i was able to get it work with @datadog/datadog-ci, we would like to use datadog without the need to set DATADOG_API_KEY (which is required on the pipeline of datadog-ci).

So is it possible to use this library without datadog-ci ?

marco-saia-datadog commented 3 months ago

Hello @ioeldev, thank you for reaching out!

I am assuming you are using our expo-datadog plugin.

Is that correct? Would you mind sharing your package.json?

marco-saia-datadog commented 3 months ago

If you are using Expo, you can disable the upload of Android sourcemaps by setting the androidSourcemaps property to false in your app.json, and re-create your project using expo prebuild --clean.

  "expo": {
    "plugins": [
      [
        "expo-datadog",
        {
          "errorTracking": {
            "androidSourcemaps": false
          }
        }
      ]
     ]
   }

Alternatively, instead of running expo prebuild --clean, you can remove the following line in your android/app/build.gradle:

apply from: "/path/to/your/project/node_modules/@datadog/mobile-react-native/datadog-sourcemaps.gradle"
ioeldev commented 3 months ago

Indeed i am using expo. Thank you for your fast reply, will try this out !

ioeldev commented 3 months ago

Seems like it's working, thank you. The datadog-ci was relevant only for the android part ? I do not need to update the expo-datadog config on the ios side ?

marco-saia-datadog commented 3 months ago

I am glad I could help!

Yes, it's better to also update the iOS side.

You can explicitly disable sourcemaps upload for both platforms with the following configuration:

{
    "androidSourcemaps": false,
    "iosDsyms": false,
    "iosSourcemaps": false
}
ioeldev commented 3 months ago

Actually it didn't work, it only worked because i just cleaned expo cace and ran the app, but when i retried to run npx expo run:ios, it prepared the builds but then throws:

Error: Cannot find module '@datadog/datadog-ci/package.json'
Require stack:
- /Users/XXX/XXX/XXX/XXX/ios/[eval]
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Function.resolve (node:internal/modules/helpers:187:19)
    at [eval]:1:57
    at runScriptInThisContext (node:internal/vm:144:10)
    at node:internal/process/execution:109:14
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:92:62)
    at evalScript (node:internal/process/execution:123:10)
    at node:internal/main/eval_string:51:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/XXX/XXX/XXX/XXX/ios/[eval]'
  ]
}

Node.js v21.1.0
Error: DATADOG_CI_EXEC does not exist or is not executable
Command PhaseScriptExecution failed with a nonzero exit code

I even removed expo-datadog from the app.json plugins array, since i just need the use DdLogger. The only datadog package i got in package.json is :

"dependencies": {
    "@apollo/client": "^3.10.6",
    "@datadog/mobile-react-native": "^2.4.1", // <------------------ HERE
    "@expo/react-native-action-sheet": "^4.1.0",
    "@expo/vector-icons": "^14.0.0",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-firebase/app": "^20.1.0",
    "@react-native-firebase/auth": "^20.1.0",
    "@react-navigation/native": "^6.0.2",
    "@segment/analytics-react-native": "^2.19.2",
    "@segment/analytics-react-native-plugin-mixpanel": "^0.4.0",
    "@segment/sovran-react-native": "^1.1.1",
    "@sentry/react-native": "~5.22.0",
    "@shopify/restyle": "^2.4.4",
    "expo": "~51.0.19",
    "expo-build-properties": "~0.12.3",
    "expo-constants": "~16.0.2",
    "expo-datadog": "^51.0.1",  // <------------------ HERE
    "expo-dev-client": "~4.0.20",
    "expo-device": "~6.0.2",
    "expo-document-picker": "~12.0.2",
    "expo-file-system": "~17.0.1",
    "expo-font": "~12.0.7",
    "expo-image": "~1.12.12",
    "expo-image-picker": "~15.0.6",
    "expo-linking": "~6.3.1",
    ...
}
marco-saia-datadog commented 3 months ago

@ioeldev

Have you set the iOS properties to false before running expo prebuild --clean?

As shown here:

{
    "androidSourcemaps": false,
    "iosDsyms": false,
    "iosSourcemaps": false
}

When the app is generated for the first time, some scripts are added to your project Build Phases, that you can find on Xcode with the names:

Cleaning the app with expo prebuild --clean after modifying your app.json is the recommended way to do it.