Skip to content

Telemetry

Avery-Dunn edited this page Aug 9, 2023 · 3 revisions

Telemetry Callback

You can register a callback to get telemetry from the authentication flow that you are conducting. To register a callback, you first define a method that receives the telemetry events. Telemetry events are sent back as List<HashMap<String, String>> .

public class Telemetry {

    private static List<HashMap<String,String>> eventsReceived = new ArrayList<>();

    public static class MyTelemetryConsumer {

        Consumer<List<HashMap<String, String>>> telemetryConsumer =
                (List<HashMap<String, String>> telemetryEvents) -> {
                    eventsReceived.addAll(telemetryEvents);
                    System.out.println("Received " + telemetryEvents.size() + " events");
                    telemetryEvents.forEach(event -> {
                        System.out.print("Event Name: " + event.get("event_name"));
                        event.entrySet().forEach(entry -> System.out.println("   " + entry));
                    });
                };
     }
}

Then register your telemetry consumer with the client application:

        PublicClientApplication app = PublicClientApplication.builder(APP_ID)
                .authority(AUTHORITY)
                .telemetryConsumer(new MyTelemetryConsumer().telemetryConsumer)
                .build();

Using that simple Consumer example above, when acquiring tokens you will see data about events printed alongside your likes, such as this one which describes a successful call to the token endpoint:

Event Name: msal.http_event   
   start_time=1691604456963
   msal.http_path=https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token
   msal.request_id_header=0ab7d6cc-e0a9-48e7-bab0-83c82ed60e01
   msal.server_error_code=0
   msal.token_age=
   elapsed_time=789
   msal.http_method=POST
   event_name=msal.http_event
   msal.server_sub_error_code=0
   msal.response_code=200
Clone this wiki locally