Skip to content

Commit

Permalink
chore: Add stack traces in exceptions and fix sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
izaaz committed Jan 26, 2024
1 parent 1ee97e6 commit 2ea2868
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.amplitude.core.Amplitude
import com.amplitude.core.events.BaseEvent
import com.amplitude.core.utilities.HttpClient
import com.amplitude.core.utilities.ResponseHandler
import com.amplitude.core.utilities.logWithStackTrace
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.channels.consumeEach
Expand Down Expand Up @@ -94,9 +95,7 @@ class EventPipeline(
if (!triggerFlush && message.event != null) try {
storage.writeEvent(message.event)
} catch (e: Exception) {
e.message?.let {
amplitude.logger.error("Error when write event: $it")
}
e.logWithStackTrace(amplitude.logger, "Error when writing event to pipeline")
}

// Skip flush when offline
Expand Down Expand Up @@ -145,9 +144,7 @@ class EventPipeline(
amplitude.logger.warn("Event storage file not found: $it")
}
} catch (e: Exception) {
e.message?.let {
amplitude.logger.error("Error when upload event: $it")
}
e.logWithStackTrace(amplitude.logger, "Error when uploading event")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.amplitude.core.Storage
import com.amplitude.core.events.BaseEvent
import com.amplitude.core.events.IdentifyOperation
import com.amplitude.core.platform.plugins.AmplitudeDestination
import com.amplitude.core.utilities.logWithStackTrace
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -107,9 +108,7 @@ class IdentifyInterceptor(
try {
storage.writeEvent(event)
} catch (e: Exception) {
e.message?.let {
logger.error("Error when write event: $it")
}
e.logWithStackTrace(logger, "Error when intercepting identifies")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.amplitude.core.utilities

import com.amplitude.common.Logger

internal fun Exception.logWithStackTrace(logger:Logger, message: String) {
this.message?.let {
logger.error("$message: $it")
}
this.stackTrace?.let {
logger.error("Stack trace: ${this.stackTraceToString()}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ public BaseEvent execute(@NonNull BaseEvent event) {
event.getEventProperties().put("custom android event property", "test");
return event;
}

@Override
public void teardown() {
}
}

0 comments on commit 2ea2868

Please sign in to comment.