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 6 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
8 changes: 7 additions & 1 deletion .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/reactnativeapp/ios/Pods/",
"src/reactnativeapp/ios/build/",
"src/reactnativeapp/android/app/build/",
"src/reactnativeapp/android/.gradle/",
"src/reactnativeapp/.expo/",
"src/reactnativeapp/expo-env.d.ts",
"internal/tools/"
]
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ the release.
([#1767](https://github.com/open-telemetry/opentelemetry-demo/pull/1767))
* [accountingservice] bump OpenTelemetry .NET Automatic Instrumentation
to 1.9.0 ([#1780](https://github.com/open-telemetry/opentelemetry-demo/pull/1780))
* [reactnativeapp] Add React Native example app
([#1781](https://github.com/open-telemetry/opentelemetry-demo/pull/1781))

## 1.12.0

Expand Down
12 changes: 11 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 @@ -191,3 +191,13 @@ else
@echo "Please provide a service name using `service=[service name]` or `SERVICE=[service name]`"
endif

src/reactnativeapp/node_modules:
npm --prefix src/reactnativeapp install

.PHONY: reactnative-android
reactnative-android: src/reactnativeapp/node_modules
npm --prefix src/reactnativeapp run android

.PHONY: reactnative-ios
reactnative-ios: src/reactnativeapp/node_modules
npm --prefix src/reactnativeapp run ios
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 reactnativeapp
gen_proto_js paymentservice
gen_proto_go productcatalogservice
# gen_proto_php quoteservice
Expand Down
3 changes: 3 additions & 0 deletions src/reactnativeapp/.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/reactnativeapp/.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",
},
};
24 changes: 24 additions & 0 deletions src/reactnativeapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store

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

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

# TODO, should we consider committing these?
protos/demo.ts
pb/demo.proto
1 change: 1 addition & 0 deletions src/reactnativeapp/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expo-env.d.ts
59 changes: 59 additions & 0 deletions src/reactnativeapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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

Unlike the other components under src/ which run within docker containers this
jpmunz marked this conversation as resolved.
Show resolved Hide resolved
app is meant to be run on either mobile emulators on your machine or physical
devices. If this is your first time running a React Native app 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).

Start the OpenTelemetry demo:

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

Before running the app the Typescript protobuf files need to be generated. This
requires at least `protoc`, if you do not have the other dev tools installed you
can comment the other invocations in `ide-gen-proto.sh` and just have
`gen_proto_ts reactnativeapp` before running:

```bash
make generate-protobuf
```

Then start the React Native app:

```bash
make reactnative-android
```

Or

```bash
make reactnative-ios
```

You can also install dependencies and launch the app directly from this folder using:

```bash
cd src/reactnativeapp
npm install
```

```bash
npm run android
```

Or

```bash
npm run ios
```
16 changes: 16 additions & 0 deletions src/reactnativeapp/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# OSX
#
.DS_Store

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/

# Bundle artifacts
*.jsbundle
172 changes: 172 additions & 0 deletions src/reactnativeapp/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()

// Use Expo CLI to bundle the app, this ensures the Metro config
// works correctly with Expo projects.
cliFile = new File(["node", "--print", "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })"].execute(null, rootDir).text.trim())
bundleCommand = "export:embed"

/* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '..'
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")

/* Variants */
// The list of variants to that are debuggable. For those we're going to
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
// debuggableVariants = ["liteDebug", "prodDebug"]

/* Bundling */
// A list containing the node command and its flags. Default is just 'node'.
// nodeExecutableAndArgs = ["node"]

//
// The path to the CLI configuration file. Default is empty.
// bundleConfig = file(../rn-cli.config.js)
//
// The name of the generated asset file containing your JS bundle
// bundleAssetName = "MyApplication.android.bundle"
//
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
// entryFile = file("../js/MyApplication.android.js")
//
// A list of extra flags to pass to the 'bundle' commands.
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
// extraPackagerArgs = []

/* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc'
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
//
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]
}
jpmunz marked this conversation as resolved.
Show resolved Hide resolved

/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()

/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'

android {
ndkVersion rootProject.ext.ndkVersion

buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion

namespace 'com.anonymous.reactnativeapp'
jpmunz marked this conversation as resolved.
Show resolved Hide resolved
defaultConfig {
applicationId 'com.anonymous.reactnativeapp'
jpmunz marked this conversation as resolved.
Show resolved Hide resolved
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
jniLibs {
useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
}
}
}

// Apply static values from `gradle.properties` to the `android.packagingOptions`
// Accepts values in comma delimited lists, example:
// android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
// Split option: 'foo,bar' -> ['foo', 'bar']
def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
// Trim all elements in place.
for (i in 0..<options.size()) options[i] = options[i].trim();
// `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
options -= ""

if (options.length > 0) {
println "android.packagingOptions.$prop += $options ($options.length)"
// Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
options.each {
android.packagingOptions[prop] += it
}
}
}

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")

def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";

if (isGifEnabled) {
// For animated gif support
implementation("com.facebook.fresco:animated-gif:${reactAndroidLibs.versions.fresco.get()}")
}

if (isWebpEnabled) {
// For webp support
implementation("com.facebook.fresco:webpsupport:${reactAndroidLibs.versions.fresco.get()}")
if (isWebpAnimatedEnabled) {
// Animated webp support
implementation("com.facebook.fresco:animated-webp:${reactAndroidLibs.versions.fresco.get()}")
}
}

if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
Binary file added src/reactnativeapp/android/app/debug.keystore
Binary file not shown.
14 changes: 14 additions & 0 deletions src/reactnativeapp/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# react-native-reanimated
-keep class com.swmansion.reanimated.** { *; }
-keep class com.facebook.react.turbomodule.** { *; }

# Add any project specific keep options here:
7 changes: 7 additions & 0 deletions src/reactnativeapp/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:usesCleartextTraffic" />
</manifest>
Loading
Loading