Skip to content

Commit

Permalink
472: set up sample app to showcase sentry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Nov 1, 2022
1 parent 7f74a23 commit 1e19afd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion android-json-form-wizard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ dependencies {
implementation "org.greenrobot:eventbus:3.2.0"
implementation 'androidx.multidex:multidex:2.0.1'

implementation 'io.sentry:sentry-android:5.0.1'
api 'io.sentry:sentry-android:5.0.1'

// PowerMock
def powerMockVersion = '2.0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.sentry.ITransaction;
import io.sentry.Sentry;
import timber.log.Timber;

import static com.vijay.jsonwizard.utils.NativeFormLangUtils.getTranslatedString;
Expand Down Expand Up @@ -84,7 +82,6 @@ public abstract class JsonFormBaseActivity extends MultiLanguageActivity impleme
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.native_form_activity_json_form);
ITransaction transaction = Sentry.startTransaction("revealFormOpening", "insideJsonFormBase oncreate");
findViewById(R.id.native_form_activity).setFilterTouchesWhenObscured(true);
mToolbar = findViewById(R.id.tb_top);
setSupportActionBar(mToolbar);
Expand Down Expand Up @@ -112,8 +109,6 @@ protected void onCreate(Bundle savedInstanceState) {
for (LifeCycleListener lifeCycleListener : lifeCycleListeners) {
lifeCycleListener.onCreate(savedInstanceState);
}

transaction.finish();
}

private String readDataSource() {
Expand Down
13 changes: 13 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ android {
versionCode 1
versionName "1.0"
multiDexEnabled true

buildConfigField("String", "SENTRY_DSN", "\"" + getProps("sentry.dsn") + "\"")
}

buildTypes {
Expand Down Expand Up @@ -60,3 +62,14 @@ dependencies {

implementation 'org.smartregister:opensrp-client-utils:0.0.6-SNAPSHOT'
}

// get property from local.properties
def getProps(String propName) {
def propsFile = rootProject.file('local.properties')
if (propsFile.exists()) {
def props = new Properties()
props.load(new FileInputStream(propsFile))
return props[propName]
}
return "";
}
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MainApplication"
android:theme="@style/NativeFormsAppTheme">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.json.JSONArray;
import org.json.JSONObject;

import io.sentry.ITransaction;
import io.sentry.Sentry;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static final int REQUEST_CODE_GET_JSON = 1234;
private static final String TAG = MainActivity.class.getCanonicalName();
Expand Down Expand Up @@ -97,6 +100,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

public void startForm(int jsonFormActivityRequestCode, String formName, String entityId, boolean translate) throws Exception {

ITransaction transaction = Sentry.startTransaction("#startForm", String.format("formName: %s", formName.toUpperCase()));

final String STEP1 = "step1";
final String FIELDS = "fields";
final String KEY = "key";
Expand Down Expand Up @@ -255,7 +260,7 @@ public void startForm(int jsonFormActivityRequestCode, String formName, String e
break;
}
}

transaction.finish();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.smartregister.nativeform;

import android.app.Application;

import io.sentry.android.core.SentryAndroid;

public class MainApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

//noinspection ConstantConditions
if (!BuildConfig.SENTRY_DSN.trim().isEmpty()) {
SentryAndroid.init(this, options -> {
options.setEnvironment("opensrp-native-form-sample");
options.setDsn(BuildConfig.SENTRY_DSN.trim());
});
}

}
}

0 comments on commit 1e19afd

Please sign in to comment.