LG 14123 Include associated user_id in event disavowal CloudWatch logs#11140
LG 14123 Include associated user_id in event disavowal CloudWatch logs#11140kevinsmaster5 merged 9 commits intomainfrom
Conversation
63cac4f to
c6f1543
Compare
There was a problem hiding this comment.
I don't think we want any changes in this file. user_id is not meant to be interpreted as a parameter for an individual analytics event, it's available for every analytics event (as properties.user_id). Properties documented in this file are logged as properties.event_properties.[property_name], which is not how we'd want user_id to be logged.
There was a problem hiding this comment.
I can't tell, but if this is a logged-out event, passing in user_id like that makes sense because user.uuid would be anonymous-uuid or something
There was a problem hiding this comment.
I think it makes sense to pass it, but I didn't think we'd want to document it here.
That being said, I did a quick audit of if we document it for other methods. It looks like we're not consistent, but document it more often than we don't. (Inconsistency expected since we don't enforce it)
Documented:
remote_logout_completeduser_registration_email_confirmationemail_and_password_authopenid_connect_tokenpassword_creationsecurity_event_receivedidv_doc_auth_submitted_image_upload_formidv_gpo_expired
Undocumented:
add_email_requestpassword_reset_emailpassword_changedidv_doc_auth_failed_image_resubmitted
There was a problem hiding this comment.
Also, I'd guess if we ever wanted to get rid of our **extra handling, we'd need to explicitly list all the keyword arguments the method could receive.
tl;dr These changes make sense after all 👍
There was a problem hiding this comment.
If you have issues in this spec file after making the changes in my previous comment, I'd consider looking at using the user argument of stub_analytics, which was implemented to support asserting a specific user being associated with the logged event.
| extra: EventDisavowal::BuildDisavowedEventAnalyticsAttributes.call(disavowed_event), | ||
| ) | ||
| analytics.event_disavowal(**result.to_h) | ||
| analytics.event_disavowal(user_id: disavowed_event.user_id, **result.to_h) |
There was a problem hiding this comment.
Should we implement this in BuildDisavowedEventAnalyticsAttributes instead? That service class pattern is not very conventional, but at least it gives us some consistency in how we build the analytics hash, and should require only updating in one place (vs. two here).
There was a problem hiding this comment.
That seems to work great.
In regards to above, should user_id be documented in analytics_events? I took it out.
There was a problem hiding this comment.
I think based on discussion it makes sense to keep the documentation.
| def create | ||
| result = password_reset_from_disavowal_form.submit(password_reset_params) | ||
| analytics.event_disavowal_password_reset(**result.to_h) | ||
| analytics.event_disavowal_password_reset(user_id: disavowed_event.user_id, **result.to_h) |
There was a problem hiding this comment.
PasswordResetFromDisavowalForm internally uses BuildDisavowedEventAnalyticsAttributes for its extra attributes, so we don't need to include this here again. One of the nice things about reusing BuildDisavowedEventAnalyticsAttributes.
| analytics.event_disavowal_password_reset(user_id: disavowed_event.user_id, **result.to_h) | |
| analytics.event_disavowal_password_reset(**result.to_h) |
| event_type: event.event_type, | ||
| event_created_at: event.created_at, | ||
| event_ip: event.ip, | ||
| user_id: event.user_id, |
There was a problem hiding this comment.
I missed it before, but confusingly user_id in the context of the Analytics class is actually referring to the user's UUID (a string), not the internal ID.
So we'd want:
| user_id: event.user_id, | |
| user_id: event.user.uuid, |
(And update documentation to refer to the value being a String, not an Int)
There was a problem hiding this comment.
Yes. The test caught that. Updated it
aduth
left a comment
There was a problem hiding this comment.
Couple comments, but tested and works well, LGTM 👍
app/services/analytics_events.rb
Outdated
| event_id: nil, | ||
| event_type: nil, | ||
| event_ip: nil, | ||
| user_id: nil, |
There was a problem hiding this comment.
Minor: I'm generally not a fan of nil defaults in the analytics keyword arguments unless there's a legitimate case for arguments not always being passed. Since we know that all of our callsites will pass user_id, and all of those user IDs will not nil, we should avoid the default, and document it as always being a string.
| expect(@analytics).to have_logged_event( | ||
| 'Event disavowal visited', | ||
| build_analytics_hash, | ||
| build_analytics_hash(user_id: event.user_id), |
There was a problem hiding this comment.
Hopefully the build will catch it, but we need to update these spec assertions to reference event.user.uuid as well.
| build_analytics_hash(user_id: event.user_id), | |
| build_analytics_hash(user_id: event.user.uuid), |
🎫 Ticket
Link to the relevant ticket:
LG-14123
🛠 Summary of changes
Passes the
disavowed_event.user.idvalue along to the respective Analytics events.📜 Testing Plan
👀 Screenshots