Skip to content

Surface msal telemetry as a long opaque string#575

Merged
rayluo merged 3 commits intodevfrom
msalruntime-telemetry
Aug 9, 2023
Merged

Surface msal telemetry as a long opaque string#575
rayluo merged 3 commits intodevfrom
msalruntime-telemetry

Conversation

@rayluo
Copy link
Contributor

@rayluo rayluo commented Jun 22, 2023

There will be a new msal_telemetry key in MSAL Python's return value. Its content is a long string which is considered opaque. Callers can store it as-is into their existing telemetry database.

The key does not always appear, so, consumer better tolerates its absence, by using result.get("msal_telemetry").

{
 "access_token": "...token...",
 "msal_telemetry": "A long long string which would contain escaped (\") and even double-escaped (\\\") quotation marks for its nested json blobs",
 "expires_in": 3600,
 "token_type": "Bearer"
}

A real world example for the long telemetry string, containing escaped (") and even double-escaped (\") quotation marks. Is that OK with you, @MSamWils ?

"msal_telemetry": "{\"msalruntime_telemetry\":{\"access_token_expiry_time\":\"2023-06-22T20:48:31.000Z\",\"additional_query_parameters_count\":\"2\",\"api_name\":\"SignInInteractively\",\"authority_type\":\"AAD\",\"authorization_type\":\"CompleteBrokerResult\",\"broker_app_used\":\"true\",\"client_id\":\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\",\"correlation_id\":\"d5ee6190-6563-4772-a94d-33fe30f017dd\",\"is_successful\":\"true\",\"msal_version\":\"1.0.0+local\",\"msalruntime_version\":\"0.11.2\",\"read_token_last_error\":\"missing required parameter\",\"request_duration\":\"17045\",\"request_eligible_for_broker\":\"true\",\"start_time\":\"2023-06-22T19:29:07.000Z\",\"stop_time\":\"2023-06-22T19:29:24.000Z\",\"ui_event_count\":\"1\",\"wam_telemetry\":\"{\\\"x_ms_clitelem\\\":\\\"1,0,0,,I\\\",\\\"ui_visible\\\":true,\\\"tenant_id\\\":\\\"72f988bf-86f1-41af-91ab-2d7cd011db47\\\",\\\"scope\\\":\\\"https://management.azure.com/.default offline_access openid profile\\\",\\\"redirect_uri\\\":\\\"ms-appx-web://Microsoft.AAD.BrokerPlugin/04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"provider_id\\\":\\\"https://login.windows.net\\\",\\\"prompt_behavior\\\":\\\"select_account\\\",\\\"http_status\\\":200,\\\"http_event_count\\\":6,\\\"device_join\\\":\\\"not_joined\\\",\\\"correlation_id\\\":\\\"{d5ee6190-6563-4772-a94d-33fe30f017dd}\\\",\\\"client_id\\\":\\\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"cache_event_count\\\":0,\\\"broker_version\\\":\\\"10.0.22000.1880\\\",\\\"authority\\\":\\\"https://login.microsoftonline.com/common\\\",\\\"api_error_code\\\":0,\\\"account_join_on_start\\\":\\\"not_joined\\\",\\\"account_join_on_end\\\":\\\"secondary\\\",\\\"account_id\\\":\\\"aa905949-a2b8-4e0a-8aea-b32e53ccdb41\\\",\\\"silent_code\\\":3399548929,\\\"silent_bi_sub_code\\\":0,\\\"silent_message\\\":\\\"Need user interaction to continue.\\\",\\\"silent_mats\\\":{\\\"ui_visible\\\":false,\\\"scope\\\":\\\"https://management.azure.com/.default offline_access openid profile\\\",\\\"redirect_uri\\\":\\\"ms-appx-web://Microsoft.AAD.BrokerPlugin/04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"provider_id\\\":\\\"https://login.windows.net\\\",\\\"oauth_error_code\\\":\\\"interaction_required\\\",\\\"device_join\\\":\\\"not_joined\\\",\\\"correlation_id\\\":\\\"{d5ee6190-6563-4772-a94d-33fe30f017dd}\\\",\\\"client_id\\\":\\\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"cache_event_count\\\":0,\\\"broker_version\\\":\\\"10.0.22000.1880\\\",\\\"authority\\\":\\\"https://login.microsoftonline.com/common\\\",\\\"api_error_code\\\":-895418367,\\\"account_join_on_start\\\":\\\"not_joined\\\",\\\"account_join_on_end\\\":\\\"not_joined\\\"},\\\"silent_status\\\":3,\\\"is_cached\\\":0}\",\"was_request_throttled\":\"false\",\"write_token\":\"AT|ID\"},\"msal_python_telemetry\":null}"

UPDATE: For now, the wam_telemetry content and its long value are removed, so that you won't see account_id in the telemetry.

@rayluo rayluo force-pushed the msalruntime-telemetry branch 3 times, most recently from 93761f5 to b5ec699 Compare June 22, 2023 19:47
@rayluo rayluo marked this pull request as ready for review June 22, 2023 19:50
@MSamWils
Copy link

There will be a new msal_telemetry key in MSAL Python's return value. Its content is a long string which is considered opaque. Callers can store it as-is into their existing telemetry database.

The key does not always appear, so, consumer better tolerates its absence, by using result.get("msal_telemetry").

{
 "access_token": "...token...",
 "msal_telemetry": "A long long string which would contain escaped (\") and even double-escaped (\\\") quotation marks for its nested json blobs",
 "expires_in": 3600,
 "token_type": "Bearer"
}

A real world example for the long telemetry string, containing escaped (") and even double-escaped (") quotation marks. Is that OK with you, @MSamWils ?

"msal_telemetry": "{\"msalruntime_telemetry\":{\"access_token_expiry_time\":\"2023-06-22T20:48:31.000Z\",\"additional_query_parameters_count\":\"2\",\"api_name\":\"SignInInteractively\",\"authority_type\":\"AAD\",\"authorization_type\":\"CompleteBrokerResult\",\"broker_app_used\":\"true\",\"client_id\":\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\",\"correlation_id\":\"d5ee6190-6563-4772-a94d-33fe30f017dd\",\"is_successful\":\"true\",\"msal_version\":\"1.0.0+local\",\"msalruntime_version\":\"0.11.2\",\"read_token_last_error\":\"missing required parameter\",\"request_duration\":\"17045\",\"request_eligible_for_broker\":\"true\",\"start_time\":\"2023-06-22T19:29:07.000Z\",\"stop_time\":\"2023-06-22T19:29:24.000Z\",\"ui_event_count\":\"1\",\"wam_telemetry\":\"{\\\"x_ms_clitelem\\\":\\\"1,0,0,,I\\\",\\\"ui_visible\\\":true,\\\"tenant_id\\\":\\\"72f988bf-86f1-41af-91ab-2d7cd011db47\\\",\\\"scope\\\":\\\"https://management.azure.com/.default offline_access openid profile\\\",\\\"redirect_uri\\\":\\\"ms-appx-web://Microsoft.AAD.BrokerPlugin/04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"provider_id\\\":\\\"https://login.windows.net\\\",\\\"prompt_behavior\\\":\\\"select_account\\\",\\\"http_status\\\":200,\\\"http_event_count\\\":6,\\\"device_join\\\":\\\"not_joined\\\",\\\"correlation_id\\\":\\\"{d5ee6190-6563-4772-a94d-33fe30f017dd}\\\",\\\"client_id\\\":\\\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"cache_event_count\\\":0,\\\"broker_version\\\":\\\"10.0.22000.1880\\\",\\\"authority\\\":\\\"https://login.microsoftonline.com/common\\\",\\\"api_error_code\\\":0,\\\"account_join_on_start\\\":\\\"not_joined\\\",\\\"account_join_on_end\\\":\\\"secondary\\\",\\\"account_id\\\":\\\"aa905949-a2b8-4e0a-8aea-b32e53ccdb41\\\",\\\"silent_code\\\":3399548929,\\\"silent_bi_sub_code\\\":0,\\\"silent_message\\\":\\\"Need user interaction to continue.\\\",\\\"silent_mats\\\":{\\\"ui_visible\\\":false,\\\"scope\\\":\\\"https://management.azure.com/.default offline_access openid profile\\\",\\\"redirect_uri\\\":\\\"ms-appx-web://Microsoft.AAD.BrokerPlugin/04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"provider_id\\\":\\\"https://login.windows.net\\\",\\\"oauth_error_code\\\":\\\"interaction_required\\\",\\\"device_join\\\":\\\"not_joined\\\",\\\"correlation_id\\\":\\\"{d5ee6190-6563-4772-a94d-33fe30f017dd}\\\",\\\"client_id\\\":\\\"04b07795-8ddb-461a-bbee-02f9e1bf7b46\\\",\\\"cache_event_count\\\":0,\\\"broker_version\\\":\\\"10.0.22000.1880\\\",\\\"authority\\\":\\\"https://login.microsoftonline.com/common\\\",\\\"api_error_code\\\":-895418367,\\\"account_join_on_start\\\":\\\"not_joined\\\",\\\"account_join_on_end\\\":\\\"not_joined\\\"},\\\"silent_status\\\":3,\\\"is_cached\\\":0}\",\"was_request_throttled\":\"false\",\"write_token\":\"AT|ID\"},\"msal_python_telemetry\":null}"

Kusto has replace or extract function to handle escape values. However, is that possible to use single quote instead of double quote in the value strings in order to reduce the number of escaped characters as well as the query runtime?

@rayluo
Copy link
Contributor Author

rayluo commented Jun 27, 2023

Kusto has replace or extract function to handle escape values. However, is that possible to use single quote instead of double quote in the value strings in order to reduce the number of escaped characters as well as the query runtime?

That long string is the standard output of a stringify algorithm. Ideally, we shall not use regex to manually parse it. Will this parse_json() function in Kusto help?

BTW, currently, the double-escape happens only because the inner wam telemetry is stringified (which also using the same double quotation mark). You could just return its original json object in MsalRuntime layer, so that MSAL Python will stringify it only once. That way, you will only need to deal with single-escape.

@rayluo rayluo force-pushed the msalruntime-telemetry branch 2 times, most recently from 5abb1c1 to 83f0b2f Compare July 23, 2023 09:16
@rayluo rayluo force-pushed the msalruntime-telemetry branch from 83f0b2f to fea7ea9 Compare July 24, 2023 09:17
@rayluo
Copy link
Contributor Author

rayluo commented Jul 24, 2023

@jiasli , this branch has been shipped as MSAL 1.24.0b1, which is also available from PyPI.

@rayluo rayluo merged commit cc8a8af into dev Aug 9, 2023
@rayluo rayluo deleted the msalruntime-telemetry branch August 9, 2023 06:24
@rayluo rayluo mentioned this pull request Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants