# Dynatrace Instrument mobile apps with Expo-Router

**URL:** <https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309>\
**Category:** Real User Monitoring\
**Tags:** mobile-monitoring\
**Created:** [October 14, 2024, 9:14am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309 "2024-10-14T09:14:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_kbs](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Simon\_kbs](https://community.dynatrace.com/u/Simon_kbs)\
**Post date:** [October 14, 2024, 9:14am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/1 "2024-10-14T09:14:43Z")

</div>

Hey Community,

we are creating a React native application using Expo and&nbsp;[expo-router](https://www.npmjs.com/package/expo-router). When trying to do the auto-instrumentation the application is loading, BUT expo is telling us that there is no route set to start from.

We tried looking for some documentation or known issues regarding expo-router but we were not able to find any. If you know more regarding the issue we encounter, the usage of Dynatrace in combination with expo-router or would need a more detailed description, feel free to comment 🙂

Cheers,

Simon

---

<div class="post-metadata">

**Author:** ![matthias\_hochri](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthias_hochri/32/15052_2.png) [@matthias\_hochri](https://community.dynatrace.com/u/matthias_hochri)\
**Post date:** [October 14, 2024, 11:24am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/2 "2024-10-14T11:24:53Z")

</div>

Hi Simon, we observed some issues in the past. I checked out the expo example:&nbsp;[expo/templates/expo-template-tabs at main · expo/expo · GitHub](https://github.com/expo/expo/tree/main/templates/expo-template-tabs)&nbsp;and tested with this and it worked for me. Did you do a prebuild with expo so the Android and iOS folder are created?

We also have an ongoing support case where we observed problems with metro.config.js. I used the following lines:

```javascript
const {getDefaultConfig} = require('expo/metro-config');
const config = getDefaultConfig(__dirname);

config.transformer.babelTransformerPath = require.resolve(
  '@dynatrace/react-native-plugin/lib/dynatrace-transformer',
);

config.reporter = require('@dynatrace/react-native-plugin/lib/dynatrace-reporter');

module.exports = config;

```

Please confirm if this helps your situation.

---

<div class="post-metadata">

**Author:** ![Simon\_kbs](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Simon\_kbs](https://community.dynatrace.com/u/Simon_kbs)\
**Post date:** [October 14, 2024, 2:42pm UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/3 "2024-10-14T14:42:01Z")

</div>

Hi Matthias, thanks for looking into it. So we’ve tried the following steps from a fresh repo:

- install dynatrace plugin.
- Add our dynatrace.config.js downloaded from the dynatrace portal.
- Setup metro:

```javascript
const {getDefaultConfig} = require('expo/metro-config');
const config = getDefaultConfig(__dirname);

config.transformer.babelTransformerPath = require.resolve(
  '@dynatrace/react-native-plugin/lib/dynatrace-transformer',
);

config.reporter = require('@dynatrace/react-native-plugin/lib/dynatrace-reporter');

module.exports = config;

```

- Setup babel

```javascript
module.exports = {
  presets: [
    [
      "babel-preset-expo",
      {
        jsxRuntime: "automatic",
        jsxImportSource: "@dynatrace/react-native-plugin",
      },
    ],
  ],
};​

```

- npx expo prebuild which create the ios and android directories.
- npx instrumentDynatrace plist=./ios/\<project\>/Info.plist as the cmd could not find the .plist file
- npx expo run:ios or npx expo run:android which result in the following:

We do see logs from dynatrace but on opening the application we do not land on our application and instead see the expo welcome screen.

 ![Simon_kbs_0-1728916006119.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/9/7927691b22ea0b66129631dbe9a18cb85b1b996f.png)

---

<div class="post-metadata">

**Author:** ![matthias\_hochri](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthias_hochri/32/15052_2.png) [@matthias\_hochri](https://community.dynatrace.com/u/matthias_hochri)\
**Post date:** [October 15, 2024, 5:08am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/4 "2024-10-15T05:08:14Z")

</div>

Thanks for your input. By fresh repo you mean your own repo or did you try the official example listed above? If you are talking about your application we probably should switch to a official support case as it takes too long in here to analyze individual files.

Your whole instructions seem to be quite alright. At least I did it pretty much the same. Only thing that I can see as a small difference is that never expo version have a slightly changed babel.config.js (Using api.cache):

```javascript
module.exports = function (api) {
  api.cache(true);
  return {
    presets: [
      ['babel-preset-expo',
        {
          jsxRuntime: 'automatic',
          jsxImportSource: '@dynatrace/react-native-plugin',
        },
      ],
    ],
  };
};

```

But I am not sure if this will make a difference as api.cache only caches the configuration used by babel.

---

<div class="post-metadata">

**Author:** ![Velcrin](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Velcrin](https://community.dynatrace.com/u/Velcrin)\
**Post date:** [October 16, 2024, 8:31am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/5 "2024-10-16T08:31:36Z")

</div>

Hey Matthias. Thank you for you support. I am working with Simon. We did actually try from the same tabs template with and without clearing api cache but without success. I created a repo that illustrate the issue&nbsp;[GitHub - velcrin/dynatrace-expo-router: A repo showing the setup to get dynatrace working with expo-router sdk 51 · GitHub](https://github.com/velcrin/dynatrace-expo-router). `main` branch is the original expo-template-tabs without any modification. It just works out of the box. The `add-dynatrace` branch is the branch were we did the setup (without `dynatrace.config.js` that we just ignored to commit). You can see the changes we made in the PR&nbsp;[Add dynatrace by velcrin · Pull Request #1 · velcrin/dynatrace-expo-router · GitHub](https://github.com/velcrin/dynatrace-expo-router/pull/1/files).&nbsp; Starting the application result in the default black expo welcome screen but should actually show the tabs demo app from the template. I’d be curious to hear if you get this working on your side.

---

<div class="post-metadata">

**Author:** ![matthias\_hochri](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthias_hochri/32/15052_2.png) [@matthias\_hochri](https://community.dynatrace.com/u/matthias_hochri)\
**Post date:** [October 16, 2024, 8:59am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/6 "2024-10-16T08:59:59Z")

</div>

Thanks for the repo. I tested and it works. I know what’s the difference. My test was on Android, yours on iOS. I will check on my MacBook next and see what happens there.

---

<div class="post-metadata">

**Author:** ![Velcrin](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Velcrin](https://community.dynatrace.com/u/Velcrin)\
**Post date:** [October 16, 2024, 3:01pm UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/7 "2024-10-16T15:01:38Z")

</div>

Android and iOS are failing for me actually. After further investigation it seems that the plugin is interfering with expo-router path used to find routes. Before using the dynatrace plugin the value of&nbsp; **EXPO\_ROUTER\_APP\_ROOT** &nbsp;is `../../app` although after applying the plugin the value is `../../../../../../../app`. Not sure what is happening. It would be interesting to debug the plugin as well. Adding an `index.js` file like described here&nbsp;[Troubleshooting - Expo documentation](https://docs.expo.dev/router/reference/troubleshooting/)&nbsp;seems to fix it. I am not exactly sure what are the implications of that change though. Anyway, fix can be tested on&nbsp;[Fix dynatrace by velcrin · Pull Request #2 · velcrin/dynatrace-expo-router · GitHub](https://github.com/velcrin/dynatrace-expo-router/pull/2/files)

---

<div class="post-metadata">

**Author:** ![matthias\_hochri](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthias_hochri/32/15052_2.png) [@matthias\_hochri](https://community.dynatrace.com/u/matthias_hochri)\
**Post date:** [October 17, 2024, 6:26am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/8 "2024-10-17T06:26:03Z")

</div>

I start to believe this a MacOS issue, because I tested Android on my Windows machine and it works. I observed basically the same thing as you. I debugged our transformer and looked at input files apart from node\_modules and saw the same&nbsp;`../../../../../../../app. Because of this it is not resolving any other application files. Android on Windows is resolving everything correctly.

So probably I will have a look today how EXPO\_ROUTER\_APP\_ROOT is defined on Mac when going the default way, to understand why our plugin is interfering here.

Thanks for the great collaboration!

---

<div class="post-metadata">

**Author:** ![matthias\_hochri](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthias_hochri/32/15052_2.png) [@matthias\_hochri](https://community.dynatrace.com/u/matthias_hochri)\
**Post date:** [October 18, 2024, 10:01am UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/9 "2024-10-18T10:01:53Z")

</div>

Okay. I found the reason. I somehow tricked myself that’s why I was telling you that Android works on my Windows machine. Turns out I found the solution while setting up the Windows project manually but I forgot about this detail.

On my Mac machine I basically debugged through the whole process to find the issue, which was the babel transformer not being called. When I looked back to my Windows Android project, it turned out that I was already using this. Following line needs to be used in our dynatrace.config.js to use the babel transformer of expo:

upstreamTransformer: require.resolve(‘@expo/metro-config/babel-transformer’)I will update our internal documentation about this.

---

<div class="post-metadata">

**Author:** ![Velcrin](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Velcrin](https://community.dynatrace.com/u/Velcrin)\
**Post date:** [October 18, 2024, 12:54pm UTC](https://community.dynatrace.com/t/dynatrace-instrument-mobile-apps-with-expo-router/48309/10 "2024-10-18T12:54:32Z")

</div>

Works like a charm! I just tried on both the dummy github project and our own. Thank you for your help!
