Skip to content
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

Add opt-in sidekiq extension for annotating delayed classes #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bf4
Copy link

@bf4 bf4 commented Sep 24, 2020

Even if no one wants to use the extension as is, it makes a good example of how one may do it.

Usage: in config/initializers/sidekiq.rb

Marginalia::SidekiqInstrumentation.enable!(annotate_delayed_class_extension: true)

optionally customize the marginalia_annotate_perform method, for example

Sidekiq::Extensions::DelayedClass.class_eval do
  def marginalia_annotate_perform(target, method_name, args)
    Rollbar.scope!(target, method_name, *args)
    "#{target}.#{method_name}"
  end
end

I would have put this in the wiki entry but I couldn't edit that, and I thought this pr may be more productive than an issue or blog post.

Even if no one wants to use the extension as is, it makes a good example of how one may do it.

Usage: in config/initializers/sidekiq.rb

```ruby
Marginalia::SidekiqInstrumentation.enable!(annotate_delayed_class_extension: true)
```
optionally customize the `marginalia_annotate_perform` method, for example

```ruby
Sidekiq::Extensions::DelayedClass.class_eval do
  def marginalia_annotate_perform(target, method_name, args)
    Rollbar.scope!(target, method_name, *args)
    "#{target}.#{method_name}"
  end
end
```
@bf4
Copy link
Author

bf4 commented Aug 16, 2021

@sj26 any thoughts on this?

@sj26
Copy link
Collaborator

sj26 commented Aug 20, 2021

Sorry @bf4, I'm not sure what this is doing? Is it reaching more deeply into Sidekiq integration to craft better annotations?

I really only jumped in to get automated testing working, and update marginalia to modern rails versions, not to introduce new features. 😅

# NOTE: Prefer redefining perform so that YAML is only parsed once.
# Adding a Marginalia::Comment.components would incur an extra parsing on every query
# in a delayed class
def perform(yml)

Choose a reason for hiding this comment

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

@bf4 Do you have a shareable sample or example Yaml block that would be used as the input here? Is this a Sidekiq thing that has serialized values for target, method_name, and args?

if annotate_delayed_class_extension
Sidekiq::Extensions::DelayedClass.class_eval do
# NOTE: Prefer redefining perform so that YAML is only parsed once.
# Adding a Marginalia::Comment.components would incur an extra parsing on every query

Choose a reason for hiding this comment

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

Did you have an example of an alternative to what was done here, but using the Marginalia::Comment.components mechanism that's documented to show this as a custom component?

I'm hunting for custom component examples.

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.

3 participants