Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a React Native example app to the demo #1781

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5086019
react native example app skeleton
jpmunz Jun 19, 2024
cde1345
Add in OpenTelemetry demo functionality
jpmunz Nov 12, 2024
3f1eb31
fix sanity check
jpmunz Nov 18, 2024
0075c67
update CHANGELOG
jpmunz Nov 18, 2024
d19f3df
Merge branch 'main' into jpmunz/react-native-example
jpmunz Nov 18, 2024
3404e12
trailing space in changelog
jpmunz Nov 18, 2024
c71232a
commit generated proto files
jpmunz Nov 19, 2024
2eace4a
use fetch and xhr instrumentations directly instead of through auto-i…
jpmunz Nov 25, 2024
6b278ed
run linter
jpmunz Nov 25, 2024
b4dc87e
switch away from deprecated addSpanProcessor
jpmunz Nov 25, 2024
f1e8fc5
fix extra span on network request
jpmunz Nov 28, 2024
9b6d92b
improve react native instructions, add a dockerfile to generate apk
jpmunz Nov 29, 2024
dbec3b7
remove demo.proto
jpmunz Nov 29, 2024
42af50d
update build android command and readme
jpmunz Dec 9, 2024
349e7c6
update steps for starting the react native app
jpmunz Dec 13, 2024
95348c7
add line breaks, remove commented lines
jpmunz Dec 16, 2024
6c61944
update package and display name
jpmunz Dec 16, 2024
62d2efc
update images
jpmunz Dec 16, 2024
ac0ff0e
remove debug exporter
jpmunz Dec 16, 2024
711dcb0
put XCode IDE build steps first
jpmunz Dec 16, 2024
d233801
Update src/reactnativeapp/README.md
jpmunz Dec 16, 2024
7b29f63
rename reactnativeapp -> react-native-app
jpmunz Dec 17, 2024
cd47bbc
update make target name
jpmunz Dec 17, 2024
76e5cbe
update ios instructions
jpmunz Dec 17, 2024
1e7f121
pin down ruby and cocoapods versions
jpmunz Dec 18, 2024
4c47720
add line break
jpmunz Dec 18, 2024
9a190ce
expand on npm run start step
jpmunz Dec 18, 2024
90d1a26
Merge branch 'upstream-main' into jpmunz/react-native-example
jpmunz Dec 19, 2024
42f7336
Merge branch 'upstream-main' into jpmunz/react-native-example
jpmunz Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ test/tracetesting/tracetesting-vars.yaml
/src/paymentservice/demo.proto
/src/shipping/proto/
/src/currencyservice/proto

# Android
*.apk
6 changes: 6 additions & 0 deletions .licenserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"src/featureflagservice/assets/vendor/",
"src/featureflagservice/priv/",
"src/productcatalogservice/genproto/",
"src/react-native-app/ios/Pods/",
"src/react-native-app/ios/build/",
"src/react-native-app/android/app/build/",
"src/react-native-app/android/.gradle/",
"src/react-native-app/.expo/",
"src/react-native-app/expo-env.d.ts",
"src/recommendationservice/demo_pb2.py",
"src/recommendationservice/demo_pb2_grpc.py",
"internal/tools/"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ the release.
([#1839](https://github.com/open-telemetry/opentelemetry-demo/pull/1839))
* [shipping] rename shippingservice to shipping
([#1842](https://github.com/open-telemetry/opentelemetry-demo/pull/1842))
* [react-native-app] Add React Native example app
([#1781](https://github.com/open-telemetry/opentelemetry-demo/pull/1781))

## 1.12.0

Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ documentation as well as the code. When making changes to any service or feature
remember to find the related docs and update those as well. Most (but not all)
documentation can be found on the OTel website under [Demo docs][docs].

### Running the React Native example

If you are interested in running the React Native example app in this repo please
review [these instructions](src/react-native-app/README.md).

## Create Your First Pull Request

### How to Send Pull Requests
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# All documents to be used in spell check.
ALL_DOCS := $(shell find . -type f -name '*.md' -not -path './.github/*' -not -path '*/node_modules/*' -not -path '*/_build/*' -not -path '*/deps/*' | sort)
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)
PWD := $(shell pwd)

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

.PHONY: build-react-native-android
build-react-native-android:
docker build -f src/react-native-app/android.Dockerfile --platform=linux/amd64 --output=. src/react-native-app
1 change: 1 addition & 0 deletions ide-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ gen_proto_go checkoutservice
# gen_proto_cpp currencyservice
# gen_proto_ruby emailservice
gen_proto_ts frontend
gen_proto_ts react-native-app
gen_proto_js paymentservice
gen_proto_go productcatalogservice
# gen_proto_php quote
Expand Down
6 changes: 6 additions & 0 deletions src/react-native-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.expo/
dist/
android/build/
ios/build/
ios/Pods/
3 changes: 3 additions & 0 deletions src/react-native-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://docs.expo.dev/guides/environment-variables/

EXPO_PUBLIC_FRONTEND_PROXY_PORT=8080
10 changes: 10 additions & 0 deletions src/react-native-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// https://docs.expo.dev/guides/using-eslint/
module.exports = {
extends: ["expo", "prettier"],
plugins: ["prettier"],
rules: {
"prettier/prettier": "error",
},
};
22 changes: 22 additions & 0 deletions src/react-native-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
pb/demo.proto

# macOS
.DS_Store

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli

1 change: 1 addition & 0 deletions src/react-native-app/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expo-env.d.ts
1 change: 1 addition & 0 deletions src/react-native-app/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.6
2 changes: 2 additions & 0 deletions src/react-native-app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'cocoapods', '1.16.2'
114 changes: 114 additions & 0 deletions src/react-native-app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (7.1.5.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
claide (1.1.0)
cocoapods (1.16.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.16.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.27.0, < 2.0)
cocoapods-core (1.16.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.17.0)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.9.1)
logger (1.6.3)
minitest (5.25.4)
molinillo (0.8.0)
mutex_m (0.3.0)
nanaimo (0.4.0)
nap (1.1.0)
netrc (0.11.0)
nkf (0.2.0)
public_suffix (4.0.7)
rexml (3.4.0)
ruby-macho (2.5.1)
securerandom (0.3.2)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.27.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.16.2)

BUNDLED WITH
2.1.4
150 changes: 150 additions & 0 deletions src/react-native-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Example React Native app

This was created using [`npx create-expo-app@latest`](https://reactnative.dev/docs/environment-setup#start-a-new-react-native-project-with-expo)

Content was taken from the web app example in src/frontend and modified to work
in a React Native environment.

## Get started

Start the OpenTelemetry demo from the root of this repo:

```bash
cd ../..
make start # or start-minimal
```

## Building the app

Unlike the other components under src/ which run within containers this
app must be built and then run on a mobile simulator on your machine or a physical
device. If this is your first time running a React Native app then in order to
execute the steps under "Build on your host machine" you will need to setup your
local environment for Android or iOS development or both following
[this guide](https://reactnative.dev/docs/set-up-your-environment). Alternatively
for Android you can instead follow the steps under "Build within a container" to
leverage a container to build the app's apk for you.

### Build on your host machine

Build and run the React Native app for a given platform by navigating to this folder
and running:

```bash
cd src/react-native-app
npm install
```

To run on Android:

```bash
npm run android
```

Note that for the above command a server is also spun up to serve the JS bundle
to the deployed app.

To run on iOS you may find it cleanest to build through the XCode IDE. First spin
up the react native dev server with the following (feel free to ignore the output
commands referring to opening an iOS simulator, we'll do that directly through
XCode in a later step):

```bash
npm run start
```

Then install the pods for the project:

```bash
cd ios
pod install
```

Note that the above is the quickest way to get going but you may end up with
slightly different versions of the Pods than what has been committed to this repo,
in order to install the precise versions first setup [rbenv](https://github.com/rbenv/rbenv#installation)
followed by:

```bash
rbenv install 2.7.6 # the version of ruby we've pinned for this app
bundle install
cd ios
bundle exec pod install
```

Then open XCode, open this as an existing project by opening `src/react-native-app/ios/react-native-app.xcworkspace`
then trigger the build by hitting the Play button or from the menu using Product->Run.

Or alternatively build and run from the command-line:

```bash
npm run ios
```

Note that for the above command a server is also spun up to serve the JS bundle
to the deployed apps.

### Build within a container

For Android builds you can produce an apk using Docker without requiring the dev
tools to be installed on your host. From the project root run:

```bash
make build-react-native-android
```

Or directly from this folder using:

```bash
docker build -f android.Dockerfile --platform=linux/amd64 --output=. .
```

This will produce `react-native-app.apk` in the directory where you ran the command.
If you have an Android emulator running on your machine then you can simply drag
and drop this file onto the emulator's window in order to install it following
[these steps](https://developer.android.com/studio/run/emulator-install-add-files).

TODO: For a physical device you can install this by sending the apk file to your
device, giving the "Install unknown apps" permission to the app you will be opening
the file with, and then installing it. However this won't be able to hit the APIs
because they are hard-coded to be localhost, need those to be configurable before
this method would work.

## Troubleshooting

### iOS build issues

If you see a build failure related to pods try forcing a clean install with and
then attempt another build after:

```bash
cd src/react-native-app/ios
rm Podfile.lock
pod cache clean --all
pod repo update --verbose
pod deintegrate
pod install --repo-update --verbose
```

If there is an error compiling or running the app try closing any open simulators
and clearing all derived data:

```bash
rm -rf ~/Library/Developer/Xcode/DerivedData
```

### Android build issues

Try stopping and cleaning local services (in case there are unknown issues related
to the start of the app):

```bash
cd src/react-native-app/android
./gradlew --stop // stop daemons
rm -rf ~/.gradle/caches/
```

### JS build issues

Try removing the `src/react-native-app/node_modules/` folder and then re-run
`npm install` from inside `src/react-native-app`.
Loading
Loading