Search in sources :

Example 6 with StartServiceLog

use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-sdk-android by Microsoft.

the class AppCenter method sendStartServiceLog.

/**
 * Queue start service log.
 */
@WorkerThread
private void sendStartServiceLog() {
    if (!mStartedServicesNamesToLog.isEmpty() && isInstanceEnabled()) {
        List<String> allServiceNamesToStart = new ArrayList<>(mStartedServicesNamesToLog);
        mStartedServicesNamesToLog.clear();
        StartServiceLog startServiceLog = new StartServiceLog();
        startServiceLog.setServices(allServiceNamesToStart);
        startServiceLog.oneCollectorEnabled(mTransmissionTargetToken != null);
        mChannel.enqueue(startServiceLog, CORE_GROUP, Flags.DEFAULTS);
    }
}
Also used : ArrayList(java.util.ArrayList) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) WorkerThread(androidx.annotation.WorkerThread)

Example 7 with StartServiceLog

use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project mobile-center-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 8 with StartServiceLog

use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project AppCenter-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 = UUIDUtils.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);
    Assert.assertEquals(log, actualContainer);
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) 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)

Example 9 with StartServiceLog

use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project AppCenter-SDK-Android by Microsoft.

the class SessionTrackerTest method ignoreStartService.

@Test
public void ignoreStartService() {
    Log startServiceLog = spy(new StartServiceLog());
    mSessionTracker.onEnqueuingLog(startServiceLog, TEST_GROUP);
    verify(mChannel, never()).enqueue(any(Log.class), anyString());
    verify(startServiceLog, never()).setSid(any(UUID.class));
}
Also used : 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 10 with StartServiceLog

use of com.microsoft.appcenter.ingestion.models.StartServiceLog in project AppCenter-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)

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