use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver in project microsoft-authentication-library-common-for-android by AzureAD.
the class TelemetryTest method testAddAndRemoveObserverSuccess.
@Test
public void testAddAndRemoveObserverSuccess() {
ITelemetryAggregatedObserver telemetryAggregatedObserver = new ITelemetryAggregatedObserver() {
@Override
public void onReceived(Map<String, String> telemetryData) {
}
};
Telemetry.getInstance().addObserver(telemetryAggregatedObserver);
Assert.assertEquals(1, Telemetry.getInstance().getObservers().size());
Assert.assertTrue(Telemetry.getInstance().getObservers().contains(telemetryAggregatedObserver));
Telemetry.getInstance().removeObserver(telemetryAggregatedObserver);
Assert.assertEquals(0, Telemetry.getInstance().getObservers().size());
Assert.assertFalse(Telemetry.getInstance().getObservers().contains(telemetryAggregatedObserver));
}
use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver 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());
}
use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver 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());
}
}
}
use of com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver in project microsoft-authentication-library-common-for-android by AzureAD.
the class TelemetryTest method testITelemetryAggregatedObserver.
@Test
public void testITelemetryAggregatedObserver() {
Telemetry.getInstance().addObserver(new ITelemetryAggregatedObserver() {
@Override
public void onReceived(Map<String, String> telemetryData) {
final String apiId = telemetryData.get(TelemetryEventStrings.Key.API_ID);
Assert.assertEquals("100", apiId);
}
});
Telemetry.emit(new ApiStartEvent().putApiId("100"));
Telemetry.getInstance().flush();
}
Aggregations