Search in sources :

Example 1 with StartServiceLog

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();
    }
}
Also used : StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) SessionContext(com.microsoft.appcenter.SessionContext) Date(java.util.Date)

Example 2 with StartServiceLog

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);
    }
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) WorkerThread(android.support.annotation.WorkerThread)

Example 3 with StartServiceLog

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));
}
Also used : AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) UUID(java.util.UUID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with StartServiceLog

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());
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) Log(com.microsoft.appcenter.ingestion.models.Log) ArrayList(java.util.ArrayList) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) UUID(java.util.UUID) Date(java.util.Date) Test(org.junit.Test)

Example 5 with StartServiceLog

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);
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) Log(com.microsoft.appcenter.ingestion.models.Log) ArrayList(java.util.ArrayList) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) UUID(java.util.UUID) Date(java.util.Date) Test(org.junit.Test)

Aggregations

StartServiceLog (com.microsoft.appcenter.ingestion.models.StartServiceLog)10 Log (com.microsoft.appcenter.ingestion.models.Log)5 Date (java.util.Date)5 UUID (java.util.UUID)5 Test (org.junit.Test)5 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)4 ArrayList (java.util.ArrayList)4 WorkerThread (android.support.annotation.WorkerThread)2 SessionContext (com.microsoft.appcenter.SessionContext)2 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 WorkerThread (androidx.annotation.WorkerThread)1 CustomPropertiesLog (com.microsoft.appcenter.ingestion.models.CustomPropertiesLog)1 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)1 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)1