Skip to content

Add custom proc support to FrontendLogger, simplify FrontendLogController#9117

Merged
aduth merged 10 commits intoaduth-try-custom-error-loggerfrom
margolis-custom-error-procify
Aug 31, 2023
Merged

Add custom proc support to FrontendLogger, simplify FrontendLogController#9117
aduth merged 10 commits intoaduth-try-custom-error-loggerfrom
margolis-custom-error-procify

Conversation

@zachmargolis
Copy link
Contributor

I nerd-sniped myself based on this comment and gave it a shot

if analytics_method.is_a?(Symbol)
analytics.send(
analytics_method,
**hash_from_kwargs(attributes, AnalyticsEvents.instance_method(analytics_method)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9e28cb8 fixes an issue with some specific events in IdV not working. I think this is also what transform_values was helping with previously, since trying to get the method signature from the analytics instance is going to have issues with how IdV::AnalyticsEventsEnhancer overrides the method and loses the signature.

| [3] pry(#<FrontendLogger>)> analytics.method(analytics_method)
=> #<Method: Analytics(Idv::AnalyticsEventsEnhancer)#idv_personal_key_acknowledgment_toggled(**kwargs) /identity-idp/app/services/idv/analytics_events_enhancer.rb:39>

define_method(method_name) do |**kwargs|

We could also consider moving this back into transform_values, and maybe there's even something where we can consolidate the handling so that the EVENT_MAP hash values are all the same type of callable thing? The issue comes with binding though... maybe we can have a small logic branch to normalize an unbound method to bind it with analytics?

analytics_method = analytics_method.bind(analytics) if analytics_method.is_a?(UnboundMethod)
analytics_method.respond_to?(:call)
  analytics_method.call(**hash_from_kwargs(attributes, analytics_method))
else
  analytics.track_event("Frontend: #{name}", attributes)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: bound vs unbound... I feel like we should have only one or the other? Seems like a lot of handling to manage both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachmargolis How do you feel about the current implementation in this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel good! 🚢

@aduth aduth merged this pull request into aduth-try-custom-error-logger Aug 31, 2023
@aduth aduth deleted the margolis-custom-error-procify branch August 31, 2023 19:03
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