Search in sources :

Example 1 with ITelemetryDefaultObserver

use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver in project microsoft-authentication-library-common-for-android by AzureAD.

the class TelemetryTest method testAddAndRemoveMultipleObserversSuccess.

@Test
public void testAddAndRemoveMultipleObserversSuccess() {
    ITelemetryAggregatedObserver telemetryAggregatedObserver = new ITelemetryAggregatedObserver() {

        @Override
        public void onReceived(Map<String, String> telemetryData) {
        }
    };
    ITelemetryDefaultObserver telemetryDefaultObserver = new ITelemetryDefaultObserver() {

        @Override
        public void onReceived(List<Map<String, String>> telemetryData) {
        }
    };
    ITelemetryObserver telemetryObserver = new ITelemetryObserver() {

        @Override
        public void onReceived(Object telemetryData) {
        }
    };
    Telemetry.getInstance().addObserver(telemetryAggregatedObserver);
    Telemetry.getInstance().addObserver(telemetryDefaultObserver);
    Telemetry.getInstance().addObserver(telemetryObserver);
    Assert.assertEquals(3, Telemetry.getInstance().getObservers().size());
    Assert.assertTrue(Telemetry.getInstance().getObservers().contains(telemetryAggregatedObserver));
    Assert.assertTrue(Telemetry.getInstance().getObservers().contains(telemetryDefaultObserver));
    Assert.assertTrue(Telemetry.getInstance().getObservers().contains(telemetryObserver));
    Telemetry.getInstance().removeObserver(telemetryDefaultObserver);
    Telemetry.getInstance().removeObserver(telemetryAggregatedObserver);
    Telemetry.getInstance().removeObserver(telemetryObserver);
    Assert.assertEquals(0, Telemetry.getInstance().getObservers().size());
}
Also used : ITelemetryDefaultObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver) ITelemetryObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryObserver) ITelemetryAggregatedObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ITelemetryDefaultObserver

use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver in project microsoft-authentication-library-common-for-android by AzureAD.

the class Telemetry method flush.

/**
 * Flush the telemetry data based on the correlation id to the observers.
 *
 * @param correlationId The correlation id should either passed by the client app through the API call
 *                      or generated by the API dispatcher.
 */
public void flush(@NonNull final String correlationId) {
    if (!mIsTelemetryEnabled) {
        return;
    }
    if (null == mObservers) {
        Logger.warn(TAG, "No telemetry observer set.");
        return;
    }
    if (StringUtil.isEmpty(correlationId)) {
        Logger.warn(TAG, "No correlation id set.");
        return;
    }
    // check the configuration
    if (!mDefaultConfiguration.isDebugEnabled() && mIsDebugging) {
        return;
    }
    List<Map<String, String>> finalRawMap = new CopyOnWriteArrayList<>();
    for (Iterator<Map<String, String>> iterator = mTelemetryRawDataMap.iterator(); iterator.hasNext(); ) {
        Map<String, String> event = iterator.next();
        if (correlationId.equalsIgnoreCase(event.get(Key.CORRELATION_ID))) {
            finalRawMap.add(applyPiiOiiRule(event));
            iterator.remove();
        }
    }
    // Add the telemetry context to the telemetry data
    finalRawMap.add(applyPiiOiiRule(mTelemetryContext.getProperties()));
    for (@SuppressWarnings(WarningType.rawtype_warning) ITelemetryObserver observer : mObservers) {
        if (observer instanceof ITelemetryAggregatedObserver) {
            new TelemetryAggregationAdapter((ITelemetryAggregatedObserver) observer).process(finalRawMap);
        } else if (observer instanceof ITelemetryDefaultObserver) {
            new TelemetryDefaultAdapter((ITelemetryDefaultObserver) observer).process(finalRawMap);
        } else {
            Logger.warn(TAG, "Unknown observer type: " + observer.getClass());
        }
    }
}
Also used : TelemetryAggregationAdapter(com.microsoft.identity.common.internal.telemetry.adapter.TelemetryAggregationAdapter) ITelemetryObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryObserver) ITelemetryDefaultObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver) TelemetryDefaultAdapter(com.microsoft.identity.common.internal.telemetry.adapter.TelemetryDefaultAdapter) ITelemetryAggregatedObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver) HashMap(java.util.HashMap) Map(java.util.Map) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with ITelemetryDefaultObserver

use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver in project microsoft-authentication-library-common-for-android by AzureAD.

the class TelemetryTest method testITelemetryDefaultObserver.

@Test
public void testITelemetryDefaultObserver() {
    Telemetry.getInstance().addObserver(new ITelemetryDefaultObserver() {

        @Override
        public void onReceived(List<Map<String, String>> telemetryData) {
            final Map<String, String> mapWithExpectedInfo = telemetryData.get(0);
            final String apiId = mapWithExpectedInfo.get(TelemetryEventStrings.Key.API_ID);
            final String authorityType = mapWithExpectedInfo.get(TelemetryEventStrings.Key.AUTHORITY_TYPE);
            Assert.assertEquals("100", apiId);
            Assert.assertEquals("AAD", authorityType);
        }
    });
    Telemetry.emit(new ApiStartEvent().putApiId("100").putAuthorityType("AAD"));
    Telemetry.getInstance().flush();
}
Also used : ITelemetryDefaultObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver) ApiStartEvent(com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ITelemetryDefaultObserver

use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver in project microsoft-authentication-library-common-for-android by AzureAD.

the class TelemetryTest method testBasicDeviceInfoPresentInTelemetry.

@Test
public void testBasicDeviceInfoPresentInTelemetry() {
    Telemetry.getInstance().addObserver(new ITelemetryDefaultObserver() {

        @Override
        public void onReceived(List<Map<String, String>> telemetryData) {
            final Map<String, String> mapWithDeviceInfo = telemetryData.get(0);
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.App.NAME));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.App.BUILD));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.Device.MODEL));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.Device.NAME));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.Os.NAME));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.Os.VERSION));
            Assert.assertTrue(mapWithDeviceInfo.containsKey(TelemetryEventStrings.Device.TIMEZONE));
        }
    });
    Telemetry.getInstance().flush();
}
Also used : ITelemetryDefaultObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ITelemetryDefaultObserver (com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver)4 Map (java.util.Map)4 Test (org.junit.Test)3 ITelemetryAggregatedObserver (com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver)2 ITelemetryObserver (com.microsoft.identity.common.internal.telemetry.observers.ITelemetryObserver)2 TelemetryAggregationAdapter (com.microsoft.identity.common.internal.telemetry.adapter.TelemetryAggregationAdapter)1 TelemetryDefaultAdapter (com.microsoft.identity.common.internal.telemetry.adapter.TelemetryDefaultAdapter)1 ApiStartEvent (com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1