use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class help method onCreate.
@Override
@AddTrace(name = "help_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
ITransaction help_create_transaction = Sentry.startTransaction("onCreate()", "help");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
try {
final SharedPreferences sharedPreferences = getSharedPreferences("publicResolverSharedPreferences", MODE_PRIVATE);
isManualDisableAnalytics = sharedPreferences.getBoolean("manualDisableAnalytics", false);
storedUniqueKey = sharedPreferences.getString("uuid", "defaultValue");
if (storedUniqueKey.contains("defaultValue")) {
uniqueKey = UUID.randomUUID().toString();
sharedPreferences.edit().putString("uuid", uniqueKey).apply();
FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
Sentry.setTag("uuid_set", "true");
Sentry.setTag("uuid_new", "true");
} else {
uniqueKey = sharedPreferences.getString("uuid", "defaultValue");
FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
Sentry.setTag("uuid_set", "true");
Sentry.setTag("uuid_new", "false");
}
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
if (isManualDisableAnalytics) {
mFirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
}
Trace remoteConfigStartTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_setup");
remoteConfigStartTrace.start();
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(1800).build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
remoteConfigStartTrace.stop();
window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Trace remoteConfigFetchTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_fetch");
remoteConfigFetchTrace.start();
mFirebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
FirebaseCrashlytics.getInstance().log("Remote config fetch succeeded: " + updated);
Sentry.addBreadcrumb("Remote config fetch succeeded: " + updated);
if (updated) {
Sentry.setTag("remote_config_fetched", "true");
} else {
Sentry.setTag("remote_config_fetched", "false");
}
mFirebaseRemoteConfig.activate();
}
}
});
remoteConfigFetchTrace.stop();
window.setStatusBarColor(ContextCompat.getColor(this, R.color.status_bar_background_color));
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.toolbar_background_color));
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network network = connectivityManager.getActiveNetwork();
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
updateVisualIndicator(linkProperties);
if (connectivityManager != null) {
connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().build(), new ConnectivityManager.NetworkCallback() {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
updateVisualIndicator(linkProperties);
}
});
}
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
help_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project NextDNSManager by mtverlee.
the class settings method onCreate.
@Override
@AddTrace(name = "settings_create", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
ITransaction settings_create_transaction = Sentry.startTransaction("onCreate()", "settings");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
try {
final SharedPreferences sharedPreferences = getSharedPreferences("mainSharedPreferences", MODE_PRIVATE);
isManualDisableAnalytics = sharedPreferences.getBoolean("manualDisableAnalytics", false);
storedUniqueKey = sharedPreferences.getString("uuid", "defaultValue");
if (storedUniqueKey.contains("defaultValue")) {
uniqueKey = UUID.randomUUID().toString();
sharedPreferences.edit().putString("uuid", uniqueKey).apply();
FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
} else {
uniqueKey = sharedPreferences.getString("uuid", "defaultValue");
FirebaseCrashlytics.getInstance().setUserId(uniqueKey);
FirebaseCrashlytics.getInstance().log("Set UUID to: " + uniqueKey);
Sentry.addBreadcrumb("Set UUID to: " + uniqueKey);
}
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
if (isManualDisableAnalytics) {
mFirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
}
Trace remoteConfigStartTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_setup");
remoteConfigStartTrace.start();
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(1800).build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
remoteConfigStartTrace.stop();
window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Trace remoteConfigFetchTrace = FirebasePerformance.getInstance().newTrace("remoteConfig_fetch");
remoteConfigFetchTrace.start();
mFirebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
FirebaseCrashlytics.getInstance().log("Remote config fetch succeeded: " + updated);
Sentry.addBreadcrumb("Remote config fetch succeeded: " + updated);
if (updated) {
Sentry.setTag("remote_config_fetched", "true");
} else {
Sentry.setTag("remote_config_fetched", "false");
}
mFirebaseRemoteConfig.activate();
}
}
});
remoteConfigFetchTrace.stop();
window.setStatusBarColor(ContextCompat.getColor(this, R.color.status_bar_background_color));
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.toolbar_background_color));
Switch manualDisableAnalytics = (Switch) findViewById(R.id.manual_disable_analytics);
versionNumber = (TextView) findViewById(R.id.versionNumberTextView);
versionNumber.setText(BuildConfig.VERSION_NAME);
ImageView whitelist = (ImageView) findViewById(R.id.whitelistImageView);
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network network = connectivityManager.getActiveNetwork();
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
updateVisualIndicator(linkProperties);
if (connectivityManager != null) {
connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().build(), new ConnectivityManager.NetworkCallback() {
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
updateVisualIndicator(linkProperties);
}
});
}
if (isManualDisableAnalytics) {
manualDisableAnalytics.setChecked(true);
} else {
manualDisableAnalytics.setChecked(false);
}
manualDisableAnalytics.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sharedPreferences.edit().putBoolean("manualDisableAnalytics", true).apply();
FirebaseCrashlytics.getInstance().log("Changed analytics to enabled.");
Sentry.addBreadcrumb("Changed analytics to enabled.");
Sentry.setTag("analytics_manual_control", "enabled");
} else {
Bundle bundle = new Bundle();
bundle.putString("id", "set_manual_disable_analytics");
mFirebaseAnalytics.logEvent("manual_disable_analytics", bundle);
sharedPreferences.edit().putBoolean("manualDisableAnalytics", false).apply();
FirebaseCrashlytics.getInstance().log("Changed analytics to disabled.");
Sentry.addBreadcrumb("Canged analytics to disabled.");
Sentry.setTag("analytics_manual_control", "disabled");
Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_SHORT).show();
}
}
});
statusIcon = (ImageView) findViewById(R.id.connectionStatus);
statusIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "help_icon");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
Intent helpIntent = new Intent(v.getContext(), help.class);
startActivity(helpIntent);
}
});
whitelist.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("https://nextdns-management.firebaseapp.com/whitelist.txt"));
startActivity(intent);
}
});
} catch (Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
Sentry.captureException(e);
} finally {
settings_create_transaction.finish();
}
}
use of com.google.firebase.perf.metrics.Trace in project capacitor-firebase by robingenz.
the class FirebasePerformance method startTrace.
public void startTrace(String traceName) {
Trace trace = this.getFirebasePerformanceInstance().newTrace(traceName);
trace.start();
this.traces.put(traceName, trace);
}
use of com.google.firebase.perf.metrics.Trace in project capacitor-firebase by robingenz.
the class FirebasePerformancePlugin method stopTrace.
@PluginMethod
public void stopTrace(PluginCall call) {
String traceName = call.getString("traceName");
if (traceName == null) {
call.reject(ERROR_TRACE_NAME_MISSING);
return;
}
Trace trace = implementation.getTraceByName(traceName);
if (trace == null) {
call.reject(ERROR_TRACE_NOT_FOUND);
return;
}
implementation.stopTrace(traceName);
call.resolve();
}
use of com.google.firebase.perf.metrics.Trace in project snippets-android by firebase.
the class MainActivity method traceCustomAttributes.
public void traceCustomAttributes() {
// [START perf_trace_custom_attrs]
Trace trace = FirebasePerformance.getInstance().newTrace("test_trace");
// Update scenario.
trace.putAttribute("experiment", "A");
// Reading scenario.
String experimentValue = trace.getAttribute("experiment");
// Delete scenario.
trace.removeAttribute("experiment");
// Read attributes.
Map<String, String> traceAttributes = trace.getAttributes();
// [END perf_trace_custom_attrs]
}
Aggregations