Skip to content

Commit

Permalink
Merge branch 'master' into lucas/remove_data_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslabari committed May 10, 2024
2 parents cb2de51 + bb925cc commit 2e692ca
Show file tree
Hide file tree
Showing 219 changed files with 913 additions and 975 deletions.
6 changes: 2 additions & 4 deletions embrace-android-sdk/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>ArgumentListWrapping:LegacyExceptionInfoTest.kt$LegacyExceptionInfoTest$( "io.embrace.android.embracesdk.LegacyExceptionInfoTest.testOfThrowable(LegacyExceptionInfoTest.kt:45)", info.lines.first())</ID>
<ID>ArgumentListWrapping:LegacyExceptionInfoTest.kt$LegacyExceptionInfoTest$("io.embrace.android.embracesdk.LegacyExceptionInfoTest.testOfThrowable(LegacyExceptionInfoTest.kt:45)", info.lines.first())</ID>
<ID>DataClassContainsFunctions:LegacyExceptionError.kt$LegacyExceptionError$fun addException(ex: Throwable?, appState: String?, clock: Clock)</ID>
<ID>DataClassContainsFunctions:LegacyExceptionError.kt$LegacyExceptionError$private fun getExceptionInfo(ex: Throwable?): List&lt;LegacyExceptionInfo&gt;</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "c") var occurrences = 0</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "rep") var exceptionErrors = mutableListOf&lt;LegacyExceptionErrorInfo&gt;()</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "c") var occurrences: Int = 0</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "rep") var exceptionErrors: MutableList&lt;LegacyExceptionErrorInfo&gt; = mutableListOf()</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import io.embrace.android.embracesdk.gating.SessionGatingKeys
import io.embrace.android.embracesdk.getSentSessionMessages
import io.embrace.android.embracesdk.hasEventOfType
import io.embrace.android.embracesdk.hasSpanOfType
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.logging.EmbLoggerImpl
import io.embrace.android.embracesdk.payload.SessionMessage
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType
Expand Down Expand Up @@ -50,7 +50,7 @@ internal class OtelSessionGatingTest {
RemoteConfig(sessionConfig = gatingConfig)
},
),
InternalEmbraceLogger()
EmbLoggerImpl()
)

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.Severity
import io.embrace.android.embracesdk.fakes.FakeLogRecordExporter
import io.embrace.android.embracesdk.fakes.FakeLoggerAction
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.fakes.FakeLogAction
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert
import org.junit.Rule
Expand Down Expand Up @@ -49,7 +48,7 @@ internal class LogRecordExporterTest {
fun `a LogRecordExporter added after initialization won't be used`() {
with(testRule) {

val fake = FakeLoggerAction()
val fake = FakeLogAction()
harness.overriddenInitModule.logger.apply { addLoggerAction(fake) }

val fakeLogRecordExporter = FakeLogRecordExporter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package io.embrace.android.embracesdk.testcases
import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.Severity
import io.embrace.android.embracesdk.fakes.FakeLogRecordExporter
import io.embrace.android.embracesdk.fakes.FakeLoggerAction
import io.embrace.android.embracesdk.fakes.FakeLogAction
import io.embrace.android.embracesdk.fakes.FakeSpanExporter
import io.embrace.android.embracesdk.opentelemetry.assertExpectedAttributes
import io.embrace.android.embracesdk.opentelemetry.assertHasEmbraceAttribute
import io.embrace.android.embracesdk.opentelemetry.embProcessIdentifier
import io.embrace.android.embracesdk.opentelemetry.embSequenceId
import io.embrace.android.embracesdk.recordSession
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
Expand Down Expand Up @@ -74,7 +71,7 @@ internal class SpanTest {
fun `a SpanExporter added after initialization won't be used`() {
with(testRule) {

val fake = FakeLoggerAction()
val fake = FakeLogAction()
harness.overriddenInitModule.logger.apply { addLoggerAction(fake) }

val fakeSpanExporter = FakeSpanExporter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import io.embrace.android.embracesdk.internal.crash.LastRunCrashVerifier;
import io.embrace.android.embracesdk.internal.spans.EmbraceTracer;
import io.embrace.android.embracesdk.internal.utils.ThrowableUtilsKt;
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger;
import io.embrace.android.embracesdk.logging.EmbLogger;
import io.embrace.android.embracesdk.logging.InternalErrorService;
import io.embrace.android.embracesdk.logging.ReportingLoggerAction;
import io.embrace.android.embracesdk.logging.InternalErrorServiceAction;
import io.embrace.android.embracesdk.ndk.NativeModule;
import io.embrace.android.embracesdk.ndk.NdkService;
import io.embrace.android.embracesdk.network.EmbraceNetworkRequest;
Expand Down Expand Up @@ -104,7 +104,7 @@ final class EmbraceImpl {
private final Clock sdkClock;

@NonNull
private final InternalEmbraceLogger internalEmbraceLogger;
private final EmbLogger logger;

/**
* Custom app ID that overrides the one specified at build time
Expand Down Expand Up @@ -209,7 +209,7 @@ final class EmbraceImpl {
EmbraceImpl(@NonNull ModuleInitBootstrapper bs) {
moduleInitBootstrapper = bs;
sdkClock = moduleInitBootstrapper.getInitModule().getClock();
internalEmbraceLogger = moduleInitBootstrapper.getInitModule().getLogger();
logger = moduleInitBootstrapper.getInitModule().getLogger();
tracer = moduleInitBootstrapper.getOpenTelemetryModule().getEmbraceTracer();
uninitializedSdkInternalInterface =
LazyKt.lazy(
Expand Down Expand Up @@ -246,7 +246,7 @@ void startInternal(@NonNull Context context,
startImpl(context, appFramework, configServiceProvider);
Systrace.endSynchronous();
} catch (Throwable t) {
internalEmbraceLogger.logError(
logger.logError(
"Error occurred while initializing the Embrace SDK. Instrumentation may be disabled.", t, true);
}
}
Expand All @@ -256,18 +256,18 @@ private void startImpl(@NonNull Context context,
@NonNull Function0<ConfigService> configServiceProvider) {
if (application != null) {
// We don't hard fail if the SDK has been already initialized.
internalEmbraceLogger.logWarning("Embrace SDK has already been initialized");
logger.logWarning("Embrace SDK has already been initialized", null, false);
return;
}

if (ApkToolsConfig.IS_SDK_DISABLED) {
internalEmbraceLogger.logInfo("SDK disabled through ApkToolsConfig");
logger.logInfo("SDK disabled through ApkToolsConfig");
stop();
return;
}

final long startTimeMs = sdkClock.now();
internalEmbraceLogger.logInfo("Starting SDK for framework " + framework.name());
logger.logInfo("Starting SDK for framework " + framework.name());
moduleInitBootstrapper.init(context, framework, startTimeMs, customAppId, configServiceProvider);
Systrace.startSynchronous("post-services-setup");
telemetryService = moduleInitBootstrapper.getInitModule().getTelemetryService();
Expand All @@ -281,7 +281,7 @@ private void startImpl(@NonNull Context context,

final EssentialServiceModule essentialServiceModule = moduleInitBootstrapper.getEssentialServiceModule();
if (essentialServiceModule.getConfigService().isSdkDisabled()) {
internalEmbraceLogger.logInfo("Interrupting SDK start because it is disabled");
logger.logInfo("Interrupting SDK start because it is disabled");
stop();
return;
}
Expand Down Expand Up @@ -369,7 +369,7 @@ private void startImpl(@NonNull Context context,

final String startMsg = "Embrace SDK started. App ID: " +
essentialServiceModule.getConfigService().getSdkModeBehavior().getAppId() + " Version: " + BuildConfig.VERSION_NAME;
internalEmbraceLogger.logInfo(startMsg);
logger.logInfo(startMsg);

final long endTimeMs = sdkClock.now();
started.set(true);
Expand Down Expand Up @@ -415,7 +415,7 @@ private void registerComposeActivityListener(@NonNull CoreModule coreModule) {
composeActivityListenerInstance = composeActivityListener.newInstance();
coreModule.getApplication().registerActivityLifecycleCallbacks((Application.ActivityLifecycleCallbacks) composeActivityListenerInstance);
} catch (Throwable e) {
internalEmbraceLogger.logError("registerComposeActivityListener error", e);
logger.logError("registerComposeActivityListener error", e, false);
}
}

Expand All @@ -428,7 +428,7 @@ private void unregisterComposeActivityListener(@NonNull Application app) {
try {
app.unregisterActivityLifecycleCallbacks((Application.ActivityLifecycleCallbacks) composeActivityListenerInstance);
} catch (Throwable e) {
internalEmbraceLogger.logError("Instantiation error for ComposeActivityListener", e);
logger.logError("Instantiation error for ComposeActivityListener", e, false);
}
}

Expand All @@ -450,16 +450,16 @@ boolean isStarted() {
*/
boolean setAppId(@NonNull String appId) {
if (isStarted()) {
internalEmbraceLogger.logError("You must set the custom app ID before the SDK is started.");
logger.logError("You must set the custom app ID before the SDK is started.", null, false);
return false;
}
if (appId.isEmpty()) {
internalEmbraceLogger.logError("App ID cannot be null or empty.");
logger.logError("App ID cannot be null or empty.", null, false);
return false;
}
if (!appIdPattern.matcher(appId).find()) {
internalEmbraceLogger.logError("Invalid app ID. Must be a 5-character string with " +
"characters from the set [A-Za-z0-9], but it was \"" + appId + "\".");
logger.logError("Invalid app ID. Must be a 5-character string with " +
"characters from the set [A-Za-z0-9], but it was \"" + appId + "\".", null, false);
return false;
}

Expand All @@ -472,7 +472,7 @@ boolean setAppId(@NonNull String appId) {
*/
void stop() {
if (started.compareAndSet(true, false)) {
internalEmbraceLogger.logInfo("Shutting down Embrace SDK.");
logger.logInfo("Shutting down Embrace SDK.");
try {
if (composeActivityListenerInstance != null && application != null) {
unregisterComposeActivityListener(application);
Expand All @@ -481,7 +481,7 @@ void stop() {
application = null;
moduleInitBootstrapper.stopServices();
} catch (Exception ex) {
internalEmbraceLogger.logError("Error while shutting down Embrace SDK", ex);
logger.logError("Error while shutting down Embrace SDK", ex, false);
}
}
}
Expand Down Expand Up @@ -662,7 +662,7 @@ void startMoment(@NonNull String name,
@Nullable String identifier,
@Nullable Map<String, Object> properties) {
if (checkSdkStartedAndLogPublicApiUsage("start_moment")) {
eventService.startEvent(name, identifier, normalizeProperties(properties, internalEmbraceLogger));
eventService.startEvent(name, identifier, normalizeProperties(properties, logger));
onActivityReported();
}
}
Expand All @@ -678,7 +678,7 @@ void startMoment(@NonNull String name,
*/
void endMoment(@NonNull String name, @Nullable String identifier, @Nullable Map<String, Object> properties) {
if (checkSdkStartedAndLogPublicApiUsage("end_moment")) {
eventService.endEvent(name, identifier, normalizeProperties(properties, internalEmbraceLogger));
eventService.endEvent(name, identifier, normalizeProperties(properties, logger));
onActivityReported();
}
}
Expand Down Expand Up @@ -811,7 +811,7 @@ void logMessage(
message,
type,
logExceptionType,
normalizeProperties(properties, internalEmbraceLogger),
normalizeProperties(properties, logger),
stackTraceElements,
customStackTrace,
appFramework,
Expand All @@ -821,7 +821,7 @@ void logMessage(
exceptionMessage);
onActivityReported();
} catch (Exception ex) {
internalEmbraceLogger.logDebug("Failed to log message using Embrace SDK.", ex);
logger.logDebug("Failed to log message using Embrace SDK.", ex);
}
}
}
Expand Down Expand Up @@ -855,7 +855,7 @@ void logInternalError(@Nullable String message, @Nullable String details) {
} else {
messageWithDetails = message;
}
internalErrorService.handleInternalError(new ReportingLoggerAction.InternalError(messageWithDetails));
internalErrorService.handleInternalError(new InternalErrorServiceAction.InternalError(messageWithDetails));
}
}

Expand Down Expand Up @@ -1000,7 +1000,7 @@ String getCurrentSessionId() {
if (sessionId != null) {
return sessionId;
} else {
internalEmbraceLogger.logInfo("Session ID is null");
logger.logInfo("Session ID is null");
}
}
return null;
Expand Down Expand Up @@ -1104,7 +1104,7 @@ void logRnAction(@NonNull String name, long startTime, long endTime,
*/
void logRnView(@NonNull String screen) {
if (appFramework != Embrace.AppFramework.REACT_NATIVE) {
internalEmbraceLogger.logWarning("[Embrace] logRnView is only available on React Native");
logger.logWarning("[Embrace] logRnView is only available on React Native", null, false);
return;
}

Expand Down Expand Up @@ -1155,21 +1155,21 @@ private void sampleCurrentThreadDuringAnrs() {
service
);
} else {
internalEmbraceLogger.logWarning("nativeThreadSamplerInstaller not started, cannot sample current thread");
logger.logWarning("nativeThreadSamplerInstaller not started, cannot sample current thread", null, false);
}
} catch (Exception exc) {
internalEmbraceLogger.logError("Failed to sample current thread during ANRs", exc);
logger.logError("Failed to sample current thread during ANRs", exc, false);
}
}

@Nullable
private Map<String, Object> normalizeProperties(@Nullable Map<String, ?> properties, @Nullable InternalEmbraceLogger logger) {
private Map<String, Object> normalizeProperties(@Nullable Map<String, ?> properties, @Nullable EmbLogger logger) {
Map<String, Object> normalizedProperties = new HashMap<>();
if (properties != null) {
try {
normalizedProperties = PropertyUtils.sanitizeProperties(properties, logger);
} catch (Exception e) {
internalEmbraceLogger.logError("Exception occurred while normalizing the properties.", e);
this.logger.logError("Exception occurred while normalizing the properties.", e, false);
}
return normalizedProperties;
} else {
Expand All @@ -1190,7 +1190,7 @@ private boolean checkSdkStartedAndLogPublicApiUsage(@NonNull String action) {
private boolean checkSdkStarted(@NonNull String action, boolean logPublicApiUsage) {
boolean isStarted = isStarted();
if (!isStarted) {
internalEmbraceLogger.logSDKNotInitialized(action);
logger.logSdkNotInitialized(action);
}
if (telemetryService != null && logPublicApiUsage) {
telemetryService.onPublicApiCalled(action);
Expand All @@ -1200,15 +1200,15 @@ private boolean checkSdkStarted(@NonNull String action, boolean logPublicApiUsag

public void addSpanExporter(@NonNull SpanExporter spanExporter) {
if (isStarted()) {
internalEmbraceLogger.logError("A SpanExporter can only be added before the SDK is started.");
logger.logError("A SpanExporter can only be added before the SDK is started.", null, false);
return;
}
moduleInitBootstrapper.getOpenTelemetryModule().getOpenTelemetryConfiguration().addSpanExporter(spanExporter);
}

public void addLogRecordExporter(@NonNull LogRecordExporter logRecordExporter) {
if (isStarted()) {
internalEmbraceLogger.logError("A LogRecordExporter can only be added before the SDK is started.");
logger.logError("A LogRecordExporter can only be added before the SDK is started.", null, false);
return;
}
moduleInitBootstrapper.getOpenTelemetryModule().getOpenTelemetryConfiguration().addLogExporter(logRecordExporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package io.embrace.android.embracesdk

import io.embrace.android.embracesdk.capture.metadata.HostedSdkVersionInfo
import io.embrace.android.embracesdk.internal.EmbraceInternalInterface
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
import io.embrace.android.embracesdk.logging.EmbLogger

internal class FlutterInternalInterfaceImpl(
private val embrace: EmbraceImpl,
private val impl: EmbraceInternalInterface,
private val hostedSdkVersionInfo: HostedSdkVersionInfo,
private val logger: InternalEmbraceLogger
private val logger: EmbLogger
) : EmbraceInternalInterface by impl, FlutterInternalInterface {

override fun setEmbraceFlutterSdkVersion(version: String?) {
Expand All @@ -17,7 +17,7 @@ internal class FlutterInternalInterfaceImpl(
hostedSdkVersionInfo.hostedSdkVersion = version
}
} else {
logger.logSDKNotInitialized("setEmbraceFlutterSdkVersion")
logger.logSdkNotInitialized("setEmbraceFlutterSdkVersion")
}
}

Expand All @@ -27,7 +27,7 @@ internal class FlutterInternalInterfaceImpl(
hostedSdkVersionInfo.hostedPlatformVersion = version
}
} else {
logger.logSDKNotInitialized("setDartVersion")
logger.logSdkNotInitialized("setDartVersion")
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ internal class FlutterInternalInterfaceImpl(
message
)
} else {
logger.logSDKNotInitialized("logDartError")
logger.logSdkNotInitialized("logDartError")
}
}
}
Loading

0 comments on commit 2e692ca

Please sign in to comment.