-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrumenting rendering of resources #1322
Conversation
600974d
to
2f4bb4a
Compare
ActiveSupport.on_load(:action_controller) do | ||
ActiveModelSerializers.logger = ActionController::Base.logger | ||
ActiveSupport.on_load(:active_model_serializers) do | ||
self.logger = ActionController::Base.logger | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bonus code, out of scope... but shouldn't be that controversial.. pattern copied from active job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty cool 👍
Looks cool 👍 |
2df3f23
to
e39dce9
Compare
require 'active_model' | ||
require 'active_support' | ||
require 'active_support/tagged_logging' | ||
require 'active_support/logger' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove these 2 requires, since we already require active_support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, for this I followed the pattern in active job
It's always nice to be explicit
You're right that it just so happens require 'active_support'
requires logging and autoloads TaggedLogging, but there's no guarantee https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support.rb#L27
That said, if you feel strongly I'll take it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we have tests covering this we are good to go, to remove.
Squashed commits: Add Logging Generates logging when renders a serializer. Tunning performance on notify_active_support - Use yield over block.call - Freeze the event name string Organize the logger architeture * Keep only the `ActiveModel::Serializer.logger` to follow the same public API we have for example to config, like `ActiveModel::Serializer.config.adapter` and remove the `ActiveModelSerializers.logger` API. * Define the logger on the load of the AMS, following the Rails convention on Railties [1], [2] and [3]. This way on non Rails apps we have a default logger and on Rails apps we will use the `Rails.logger` the same way that Active Job do [4]. [1]: https://github.com/rails/rails/blob/2ad9afe4ff2c12d1a9e4a00d9009d040e636c9b0/activejob/lib/active_job/railtie.rb#L9-L11 [2]: https://github.com/rails/rails/blob/2ad9afe4ff2c12d1a9e4a00d9009d040e636c9b0/activerecord/lib/active_record/railtie.rb#L75-L77 [3]: https://github.com/rails/rails/blob/2ad9afe4ff2c12d1a9e4a00d9009d040e636c9b0/actionview/lib/action_view/railtie.rb#L19-L21 [4]: https://github.com/rails/rails/blob/2ad9afe4ff2c12d1a9e4a00d9009d040e636c9b0/activejob/lib/active_job/logging.rb#L10-L11 Performance tunning on LogSubscriber#render Move the definition of locals to inside the `info` block this way the code is executed only when the logger is called. Remove not needed check on SerializableResource Use SerializableResource on ActionController integration On the ActionController was using a adapter, and since the instrumentation is made on the SerializableResource we need to use the SerializableResource over the adapter directly. Otherwise the logger is not called on a Rails app. Use SerializableResource on the ActionController, since this is the main interface to create and call a serializer. Using always the SerializableResource we can keep the adapter code more easy to mantain since no Adapter will need to call the instrumentation, only the SerializableResource care about this. Add docs about logging Add a CHANGELOG entry Keep the ActiveModelSerializers.logger Better wording on Logging docs [ci skip] Add doc about instrumentation [ci skip] Use ActiveModel::Callbacks on the SerializableResource
fcb8b05
to
d4fc811
Compare
@maurogeorge updated with two incremental commits responding to your feedback, for easy review |
@bf4 I am ok with that 👍 |
@@ -0,0 +1,19 @@ | |||
# Instrumentation | |||
|
|||
ActiveModelSerializers uses the ActiveSupport::Notification API, which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should there be an example here of how to tie this in to the Notification API?
end | ||
end | ||
|
||
# Macros that can be used to customize the logging of class or instance methods, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is some solid documentation :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied pretty much :)
B mobile phone
On Nov 10, 2015, at 8:22 AM, L. Preston Sego III notifications@github.com wrote:
In lib/active_model_serializers/logging.rb:
instrument_rendering
- end
- module ClassMethods
def instrument_rendering
around_render do |args, block|
tag_logger do
notify_render do
block.call(args)
end
end
end
end
- end
Macros that can be used to customize the logging of class or instance methods,
this is some solid documentation :-)
—
Reply to this email directly or view it on GitHub.
Appveyour failure is transitory |
Is this waiting on anything? Would love to get to work on Skylight integration once this is official :) |
@wagenet not sure. Have you tried Otherwise, I just need to rebase it |
@bf4 I am ok with that |
per NullVoxPopuli comment
d4fc811
to
733f5bc
Compare
Instrumenting rendering of resources
Merged |
Thanks 🎉 🎊 |
Thanks! Haven't had a chance to use it yet, but hope to soon :) |
Started to play around with this some. Looks good to me so far! |
Building on the very excellent PR by @maurogeorge (all squashed)
#1291