use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-sdk-android by Microsoft.
the class SessionTracker method onEnqueuingLog.
@Override
public void onEnqueuingLog(@NonNull Log log, @NonNull String groupName) {
/*
* Since we enqueue start session logs, skip them to avoid infinite loop.
* Also skip start service log as it's always sent and should not trigger a session.
*/
if (log instanceof StartSessionLog || log instanceof StartServiceLog) {
return;
}
/*
* If the log has already specified a timestamp, try correlating with a past session.
* Note that it can also find the current session but that's ok: in that case that means
* its a log that will be associated to current session but won't trigger expiration logic.
*/
Date timestamp = log.getTimestamp();
if (timestamp != null) {
SessionContext.SessionInfo pastSession = SessionContext.getInstance().getSessionAt(timestamp.getTime());
if (pastSession != null) {
log.setSid(pastSession.getSessionId());
}
} else /* If the log does not have a timestamp yet, then we just correlate with current session. */
{
/* Send a new start session log if needed. */
sendStartSessionIfNeeded();
/* Set current session identifier. */
log.setSid(mSid);
/* Record queued time only if the log is using current session. */
mLastQueuedLogTime = SystemClock.elapsedRealtime();
}
}
use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project AppCenter-SDK-Android by Microsoft.
the class AppCenter method sendStartServiceLog.
/**
* Queue start service log.
*
* @param serviceNames the services to send.
*/
@WorkerThread
private void sendStartServiceLog(List<String> serviceNames) {
if (isInstanceEnabled()) {
StartServiceLog startServiceLog = new StartServiceLog();
startServiceLog.setServices(serviceNames);
mChannel.enqueue(startServiceLog, CORE_GROUP);
} else {
if (mStartedServicesNamesToLog == null) {
mStartedServicesNamesToLog = new ArrayList<>();
}
mStartedServicesNamesToLog.addAll(serviceNames);
}
}
use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method ignoreStartService.
@Test
public void ignoreStartService() {
Log startServiceLog = spy(new StartServiceLog());
mSessionTracker.onPreparingLog(startServiceLog, TEST_GROUP);
verify(mChannel, never()).enqueue(any(Log.class), anyString(), anyInt());
verify(startServiceLog, never()).setSid(any(UUID.class));
}
use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-sdk-android by Microsoft.
the class LogSerializerAndroidTest method readJsonWhenIsOneCollectorPropertyEnabledIsNull.
@Test
public void readJsonWhenIsOneCollectorPropertyEnabledIsNull() throws JSONException {
// Prepare start service log.
StartServiceLog serviceLog = new StartServiceLog();
List<String> services = new ArrayList<>();
services.add("FIRST");
services.add("SECOND");
serviceLog.setServices(services);
UUID sid = UUID.randomUUID();
serviceLog.setSid(sid);
serviceLog.setTimestamp(new Date());
// Prepare log container.
ArrayList<Log> logArrayList = new ArrayList<>();
logArrayList.add(serviceLog);
LogContainer serializerContainer = new LogContainer();
serializerContainer.setLogs(logArrayList);
// Serializer log container.
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory());
String payload = serializer.serializeContainer(serializerContainer);
// Deserialize log container.
LogContainer deserializeContainer = serializer.deserializeContainer(payload, null);
StartServiceLog deserializeStartServiceLog = (StartServiceLog) deserializeContainer.getLogs().get(0);
Assert.assertNull(deserializeStartServiceLog.isOneCollectorEnabled());
}
use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-sdk-android by Microsoft.
the class LogSerializerAndroidTest method startServiceLog.
@Test
public void startServiceLog() throws JSONException {
StartServiceLog log = new StartServiceLog();
List<String> services = new ArrayList<>();
services.add("FIRST");
services.add("SECOND");
log.setServices(services);
UUID sid = UUID.randomUUID();
log.setSid(sid);
log.setTimestamp(new Date());
/* Verify serialize and deserialize. */
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory());
String payload = serializer.serializeLog(log);
Log actualContainer = serializer.deserializeLog(payload, null);
assertEquals(log, actualContainer);
}
Aggregations