Open raivil opened 4 years ago
For now I think you should be able to use Yabeda.with_tags
and memoization in yabeda_tags
to achieve the same result without changes in middlewares. Something like this:
class MyJobs::JobName
include Sidekiq::Worker
def perform(id)
Yabeda.with_tags(yabeda_tags) do
Customer.find(id).do_super_important_stuff
end
end
def yabeda_tags
@yabeda_tags ||= { importance: 'super important' }
end
end
I'm not sure whether or not yabeda-sidekiq should use Yabeda.with_tags
by default in server middleware. Inside Yabeda.with_tags
these tags will be added to all metrics, not only to sidekiq-specific ones. And some users tracks app-specific things from code executed within sidekiq jobs. I just not sure which behavior is more expected.
Hey @Envek, I've started using the exporter and I'm trying to set it up to use dynamic tags. This is a continuation of https://github.com/yabeda-rb/yabeda/issues/12.
Using the existing method
def yabeda_tags(*params)
works but it has one drawback. If the job needs to retrieve the tag from a database or other external source, it may do repeated queries that would be executed on theperform
method already.Example of duplicated database calls below. It could get more complicated depending on the job.
Ideally, if the
Yabeda.with_tags
worked inside the job, it would solve all problems, but since Sidekiq uses a middleware chain, I'm not sure if it's possible.I checked the Yabeda middlewares on this project and changed ServerMiddleware a little bit to work with
Thread.current[:yabeda_temporary_tags]
, the same strategy aswith_tags
.Sidekiq config to remove existing middleware and add the new one.
What do you think about this strategy? Any points that draw your attention? Can you see alternatives to it?
Best,