aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.41k stars 346 forks source link

auth: add telemetry for why the user needed to reauth #5243

Open nkomonen-amazon opened 6 days ago

nkomonen-amazon commented 6 days ago

Problem:

In the reauth metric (aws_loginWithBrowser + isReAuth: true) we didn't know why the user needed to reauth. It could have been due to regular expiration or some unexpected error.

Solution:

Add a new field in aws_loginWithBrowser named reAuthReason which will have some sort of identifier for why reauth was needed.

On a technical level, we save the reason an SSO connection was invalidated in our cache using the ReAuthReasonState class. Then when it comes time to do a reauth we will grab the past value from that state and set it in the metric.

The reauth reason can be set in a few places, but some examples are when the token refresh process fails, we will know that this is the cause for the user needing to reauth.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

justinmk3 commented 6 days ago

Thought experiement: in the places where this PR currently calls, ReAuthReasonState.setReason, why can't we use telemetry.aws_loginWithBrowser.record({reAuthReason: ...}) instead?

If the answer is "because the execution context might be lost by the time we emit telemetry.aws_loginWithBrowser, then next questions are: