Skip to content

Commit cb75eba

Browse files
authored
Add a React Native example app to the demo (#1781)
1 parent fca8fd1 commit cb75eba

File tree

129 files changed

+29198
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+29198
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ test/tracetesting/tracetesting-vars.yaml
5555
/src/paymentservice/demo.proto
5656
/src/shipping/proto/
5757
/src/currencyservice/proto
58+
59+
# Android
60+
*.apk

.licenserc.json

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
"src/featureflagservice/assets/vendor/",
4646
"src/featureflagservice/priv/",
4747
"src/productcatalogservice/genproto/",
48+
"src/react-native-app/ios/Pods/",
49+
"src/react-native-app/ios/build/",
50+
"src/react-native-app/android/app/build/",
51+
"src/react-native-app/android/.gradle/",
52+
"src/react-native-app/.expo/",
53+
"src/react-native-app/expo-env.d.ts",
4854
"src/recommendationservice/demo_pb2.py",
4955
"src/recommendationservice/demo_pb2_grpc.py",
5056
"internal/tools/"

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ the release.
4646
([#1839](https://github.com/open-telemetry/opentelemetry-demo/pull/1839))
4747
* [shipping] rename shippingservice to shipping
4848
([#1842](https://github.com/open-telemetry/opentelemetry-demo/pull/1842))
49+
* [react-native-app] Add React Native example app
50+
([#1781](https://github.com/open-telemetry/opentelemetry-demo/pull/1781))
4951

5052
## 1.12.0
5153

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ documentation as well as the code. When making changes to any service or feature
103103
remember to find the related docs and update those as well. Most (but not all)
104104
documentation can be found on the OTel website under [Demo docs][docs].
105105

106+
### Running the React Native example
107+
108+
If you are interested in running the React Native example app in this repo please
109+
review [these instructions](src/react-native-app/README.md).
110+
106111
## Create Your First Pull Request
107112

108113
### How to Send Pull Requests

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
# All documents to be used in spell check.
6-
ALL_DOCS := $(shell find . -type f -name '*.md' -not -path './.github/*' -not -path '*/node_modules/*' -not -path '*/_build/*' -not -path '*/deps/*' | sort)
6+
ALL_DOCS := $(shell find . -type f -name '*.md' -not -path './.github/*' -not -path '*/node_modules/*' -not -path '*/_build/*' -not -path '*/deps/*' -not -path */Pods/* -not -path */.expo/* | sort)
77
PWD := $(shell pwd)
88

99
TOOLS_DIR := ./internal/tools
@@ -218,3 +218,6 @@ else
218218
@echo "Please provide a service name using `service=[service name]` or `SERVICE=[service name]`"
219219
endif
220220

221+
.PHONY: build-react-native-android
222+
build-react-native-android:
223+
docker build -f src/react-native-app/android.Dockerfile --platform=linux/amd64 --output=. src/react-native-app

ide-gen-proto.sh

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ gen_proto_go checkoutservice
7272
# gen_proto_cpp currencyservice
7373
# gen_proto_ruby emailservice
7474
gen_proto_ts frontend
75+
gen_proto_ts react-native-app
7576
gen_proto_js paymentservice
7677
gen_proto_go productcatalogservice
7778
# gen_proto_php quote

src/react-native-app/.dockerignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.expo/
3+
dist/
4+
android/build/
5+
ios/build/
6+
ios/Pods/

src/react-native-app/.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://docs.expo.dev/guides/environment-variables/
2+
3+
EXPO_PUBLIC_FRONTEND_PROXY_PORT=8080

src/react-native-app/.eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
// https://docs.expo.dev/guides/using-eslint/
4+
module.exports = {
5+
extends: ["expo", "prettier"],
6+
plugins: ["prettier"],
7+
rules: {
8+
"prettier/prettier": "error",
9+
},
10+
};

src/react-native-app/.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
node_modules/
2+
.expo/
3+
dist/
4+
npm-debug.*
5+
*.jks
6+
*.p8
7+
*.p12
8+
*.key
9+
*.mobileprovision
10+
*.orig.*
11+
web-build/
12+
pb/demo.proto
13+
14+
# macOS
15+
.DS_Store
16+
17+
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
18+
# The following patterns were generated by expo-cli
19+
20+
expo-env.d.ts
21+
# @end expo-cli
22+

src/react-native-app/.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
expo-env.d.ts

src/react-native-app/.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.6

src/react-native-app/Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'cocoapods', '1.16.2'

src/react-native-app/Gemfile.lock

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
7+
rexml
8+
activesupport (7.1.5.1)
9+
base64
10+
benchmark (>= 0.3)
11+
bigdecimal
12+
concurrent-ruby (~> 1.0, >= 1.0.2)
13+
connection_pool (>= 2.2.5)
14+
drb
15+
i18n (>= 1.6, < 2)
16+
logger (>= 1.4.2)
17+
minitest (>= 5.1)
18+
mutex_m
19+
securerandom (>= 0.3)
20+
tzinfo (~> 2.0)
21+
addressable (2.8.7)
22+
public_suffix (>= 2.0.2, < 7.0)
23+
algoliasearch (1.27.5)
24+
httpclient (~> 2.8, >= 2.8.3)
25+
json (>= 1.5.1)
26+
atomos (0.1.3)
27+
base64 (0.2.0)
28+
benchmark (0.4.0)
29+
bigdecimal (3.1.8)
30+
claide (1.1.0)
31+
cocoapods (1.16.2)
32+
addressable (~> 2.8)
33+
claide (>= 1.0.2, < 2.0)
34+
cocoapods-core (= 1.16.2)
35+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
36+
cocoapods-downloader (>= 2.1, < 3.0)
37+
cocoapods-plugins (>= 1.0.0, < 2.0)
38+
cocoapods-search (>= 1.0.0, < 2.0)
39+
cocoapods-trunk (>= 1.6.0, < 2.0)
40+
cocoapods-try (>= 1.1.0, < 2.0)
41+
colored2 (~> 3.1)
42+
escape (~> 0.0.4)
43+
fourflusher (>= 2.3.0, < 3.0)
44+
gh_inspector (~> 1.0)
45+
molinillo (~> 0.8.0)
46+
nap (~> 1.0)
47+
ruby-macho (>= 2.3.0, < 3.0)
48+
xcodeproj (>= 1.27.0, < 2.0)
49+
cocoapods-core (1.16.2)
50+
activesupport (>= 5.0, < 8)
51+
addressable (~> 2.8)
52+
algoliasearch (~> 1.0)
53+
concurrent-ruby (~> 1.1)
54+
fuzzy_match (~> 2.0.4)
55+
nap (~> 1.0)
56+
netrc (~> 0.11)
57+
public_suffix (~> 4.0)
58+
typhoeus (~> 1.0)
59+
cocoapods-deintegrate (1.0.5)
60+
cocoapods-downloader (2.1)
61+
cocoapods-plugins (1.0.0)
62+
nap
63+
cocoapods-search (1.0.1)
64+
cocoapods-trunk (1.6.0)
65+
nap (>= 0.8, < 2.0)
66+
netrc (~> 0.11)
67+
cocoapods-try (1.2.0)
68+
colored2 (3.1.2)
69+
concurrent-ruby (1.3.4)
70+
connection_pool (2.4.1)
71+
drb (2.2.1)
72+
escape (0.0.4)
73+
ethon (0.16.0)
74+
ffi (>= 1.15.0)
75+
ffi (1.17.0)
76+
fourflusher (2.3.1)
77+
fuzzy_match (2.0.4)
78+
gh_inspector (1.1.3)
79+
httpclient (2.8.3)
80+
i18n (1.14.6)
81+
concurrent-ruby (~> 1.0)
82+
json (2.9.1)
83+
logger (1.6.3)
84+
minitest (5.25.4)
85+
molinillo (0.8.0)
86+
mutex_m (0.3.0)
87+
nanaimo (0.4.0)
88+
nap (1.1.0)
89+
netrc (0.11.0)
90+
nkf (0.2.0)
91+
public_suffix (4.0.7)
92+
rexml (3.4.0)
93+
ruby-macho (2.5.1)
94+
securerandom (0.3.2)
95+
typhoeus (1.4.1)
96+
ethon (>= 0.9.0)
97+
tzinfo (2.0.6)
98+
concurrent-ruby (~> 1.0)
99+
xcodeproj (1.27.0)
100+
CFPropertyList (>= 2.3.3, < 4.0)
101+
atomos (~> 0.1.3)
102+
claide (>= 1.0.2, < 2.0)
103+
colored2 (~> 3.1)
104+
nanaimo (~> 0.4.0)
105+
rexml (>= 3.3.6, < 4.0)
106+
107+
PLATFORMS
108+
ruby
109+
110+
DEPENDENCIES
111+
cocoapods (= 1.16.2)
112+
113+
BUNDLED WITH
114+
2.1.4

src/react-native-app/README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Example React Native app
2+
3+
This was created using [`npx create-expo-app@latest`](https://reactnative.dev/docs/environment-setup#start-a-new-react-native-project-with-expo)
4+
5+
Content was taken from the web app example in src/frontend and modified to work
6+
in a React Native environment.
7+
8+
## Get started
9+
10+
Start the OpenTelemetry demo from the root of this repo:
11+
12+
```bash
13+
cd ../..
14+
make start # or start-minimal
15+
```
16+
17+
## Building the app
18+
19+
Unlike the other components under src/ which run within containers this
20+
app must be built and then run on a mobile simulator on your machine or a physical
21+
device. If this is your first time running a React Native app then in order to
22+
execute the steps under "Build on your host machine" you will need to setup your
23+
local environment for Android or iOS development or both following
24+
[this guide](https://reactnative.dev/docs/set-up-your-environment). Alternatively
25+
for Android you can instead follow the steps under "Build within a container" to
26+
leverage a container to build the app's apk for you.
27+
28+
### Build on your host machine
29+
30+
Build and run the React Native app for a given platform by navigating to this folder
31+
and running:
32+
33+
```bash
34+
cd src/react-native-app
35+
npm install
36+
```
37+
38+
To run on Android:
39+
40+
```bash
41+
npm run android
42+
```
43+
44+
Note that for the above command a server is also spun up to serve the JS bundle
45+
to the deployed app.
46+
47+
To run on iOS you may find it cleanest to build through the XCode IDE. First spin
48+
up the react native dev server with the following (feel free to ignore the output
49+
commands referring to opening an iOS simulator, we'll do that directly through
50+
XCode in a later step):
51+
52+
```bash
53+
npm run start
54+
```
55+
56+
Then install the pods for the project:
57+
58+
```bash
59+
cd ios
60+
pod install
61+
```
62+
63+
Note that the above is the quickest way to get going but you may end up with
64+
slightly different versions of the Pods than what has been committed to this repo,
65+
in order to install the precise versions first setup [rbenv](https://github.com/rbenv/rbenv#installation)
66+
followed by:
67+
68+
```bash
69+
rbenv install 2.7.6 # the version of ruby we've pinned for this app
70+
bundle install
71+
cd ios
72+
bundle exec pod install
73+
```
74+
75+
Then open XCode, open this as an existing project by opening `src/react-native-app/ios/react-native-app.xcworkspace`
76+
then trigger the build by hitting the Play button or from the menu using Product->Run.
77+
78+
Or alternatively build and run from the command-line:
79+
80+
```bash
81+
npm run ios
82+
```
83+
84+
Note that for the above command a server is also spun up to serve the JS bundle
85+
to the deployed apps.
86+
87+
### Build within a container
88+
89+
For Android builds you can produce an apk using Docker without requiring the dev
90+
tools to be installed on your host. From the project root run:
91+
92+
```bash
93+
make build-react-native-android
94+
```
95+
96+
Or directly from this folder using:
97+
98+
```bash
99+
docker build -f android.Dockerfile --platform=linux/amd64 --output=. .
100+
```
101+
102+
This will produce `react-native-app.apk` in the directory where you ran the command.
103+
If you have an Android emulator running on your machine then you can simply drag
104+
and drop this file onto the emulator's window in order to install it following
105+
[these steps](https://developer.android.com/studio/run/emulator-install-add-files).
106+
107+
TODO: For a physical device you can install this by sending the apk file to your
108+
device, giving the "Install unknown apps" permission to the app you will be opening
109+
the file with, and then installing it. However this won't be able to hit the APIs
110+
because they are hard-coded to be localhost, need those to be configurable before
111+
this method would work.
112+
113+
## Troubleshooting
114+
115+
### iOS build issues
116+
117+
If you see a build failure related to pods try forcing a clean install with and
118+
then attempt another build after:
119+
120+
```bash
121+
cd src/react-native-app/ios
122+
rm Podfile.lock
123+
pod cache clean --all
124+
pod repo update --verbose
125+
pod deintegrate
126+
pod install --repo-update --verbose
127+
```
128+
129+
If there is an error compiling or running the app try closing any open simulators
130+
and clearing all derived data:
131+
132+
```bash
133+
rm -rf ~/Library/Developer/Xcode/DerivedData
134+
```
135+
136+
### Android build issues
137+
138+
Try stopping and cleaning local services (in case there are unknown issues related
139+
to the start of the app):
140+
141+
```bash
142+
cd src/react-native-app/android
143+
./gradlew --stop // stop daemons
144+
rm -rf ~/.gradle/caches/
145+
```
146+
147+
### JS build issues
148+
149+
Try removing the `src/react-native-app/node_modules/` folder and then re-run
150+
`npm install` from inside `src/react-native-app`.

0 commit comments

Comments
 (0)