From 75a94f08a9e15d428d5bc0c1eb46ff4a42f13b1c Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Wed, 6 Nov 2024 17:20:40 +0100 Subject: [PATCH] Reformat file. Bring previous metrics logic --- .../backtraceio/library/common/ApplicationHelper.java | 11 +++++++---- .../library/services/BacktraceMetrics.java | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backtrace-library/src/main/java/backtraceio/library/common/ApplicationHelper.java b/backtrace-library/src/main/java/backtraceio/library/common/ApplicationHelper.java index 2d8a7665..ae70b9c3 100644 --- a/backtrace-library/src/main/java/backtraceio/library/common/ApplicationHelper.java +++ b/backtrace-library/src/main/java/backtraceio/library/common/ApplicationHelper.java @@ -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 { @@ -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(); diff --git a/backtrace-library/src/main/java/backtraceio/library/services/BacktraceMetrics.java b/backtrace-library/src/main/java/backtraceio/library/services/BacktraceMetrics.java index 7e14fac1..6bf7f9fb 100644 --- a/backtrace-library/src/main/java/backtraceio/library/services/BacktraceMetrics.java +++ b/backtrace-library/src/main/java/backtraceio/library/services/BacktraceMetrics.java @@ -4,7 +4,6 @@ import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentLinkedDeque; @@ -12,6 +11,7 @@ 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; @@ -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"); } /**