Skip to content

Commit

Permalink
Reformat file. Bring previous metrics logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Dysput committed Nov 6, 2024
1 parent 79fa883 commit 75a94f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ public class ApplicationHelper {

/**
* Retrieves application name from context. The name will be cached over checks
*
* @param context application context
* @return application name
*/
public static String getApplicationName(Context context) {
if(!BacktraceStringHelper.isNullOrEmpty(applicationName)) {
if (!BacktraceStringHelper.isNullOrEmpty(applicationName)) {
return applicationName;
}

applicationName = context.getApplicationInfo().loadLabel(context.getPackageManager()).toString();
return applicationName;
return applicationName;
}

/**
* Retrieves application version from the context. If the version name is not defined, the version code will be used instead.
*
* @param context application context
* @return current application version.
*/
public static String getApplicationVersion(Context context) {
if(!BacktraceStringHelper.isNullOrEmpty(applicationVersion)) {
if (!BacktraceStringHelper.isNullOrEmpty(applicationVersion)) {
return applicationVersion;
}
try {
Expand All @@ -60,11 +62,12 @@ public static String getApplicationVersion(Context context) {

/**
* Retrieves package name from the context.
*
* @param context application context
* @return current package name.
*/
public static String getPackageName(Context context) {
if(!BacktraceStringHelper.isNullOrEmpty(packageName)) {
if (!BacktraceStringHelper.isNullOrEmpty(packageName)) {
return packageName;
}
packageName = context.getApplicationContext().getPackageName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedDeque;

import backtraceio.library.BacktraceCredentials;
import backtraceio.library.common.ApplicationHelper;
import backtraceio.library.common.BacktraceStringHelper;
import backtraceio.library.common.BacktraceTimeHelper;
import backtraceio.library.common.serialization.DebugHelper;
import backtraceio.library.events.EventsOnServerResponseEventListener;
import backtraceio.library.events.EventsRequestHandler;
import backtraceio.library.interfaces.Api;
Expand Down Expand Up @@ -184,15 +184,21 @@ public void enable(BacktraceMetricsSettings settings, String uniqueEventName) {

this.applicationName = ApplicationHelper.getApplicationName(this.getContext());
this.applicationVersion = ApplicationHelper.getApplicationVersion(this.getContext());
setStartupUniqueEventName(uniqueEventName);
final long startMetricsSetup = DebugHelper.getCurrentTimeMillis();

setStartupUniqueEventName(uniqueEventName);
this.settings = settings;
this.enabled = true;
try {
startMetricsEventHandlers(backtraceApi);
sendStartupEvent();
BacktraceLogger.d(LOG_TAG, "Metrics enabled");
} catch (Exception e) {
BacktraceLogger.e(LOG_TAG, "Could not enable metrics, exception " + e.getMessage());
}
final long endMetricsSetup = DebugHelper.getCurrentTimeMillis();
BacktraceLogger.d(LOG_TAG, "Setup metrics integration took " + (endMetricsSetup - startMetricsSetup) + " milliseconds");
}

/**
Expand Down

0 comments on commit 75a94f0

Please sign in to comment.