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

Include sidekiq job class in log tags? #256

Open
jdelStrother opened this issue Jan 10, 2025 · 0 comments
Open

Include sidekiq job class in log tags? #256

jdelStrother opened this issue Jan 10, 2025 · 0 comments

Comments

@jdelStrother
Copy link

Environment

Provide at least:

  • Ruby Version. 3.3
  • Rails Version. 7.2
  • Semantic Logger Version. 4.16
  • Rails Semantic Logger Version. 4.17
  • Sidekiq 7.3.7

Expected Behavior

Sidekiq's default job logger tags the logs with the job class:

2025-01-10T10:23:27.148Z pid=47763 tid=15bv class=SimpleWorker jid=38c1f5938b17233b4e0b842b INFO: start
2025-01-10T10:23:27.160Z pid=47763 tid=15bv class=SimpleWorker jid=38c1f5938b17233b4e0b842b INFO: Hello world
2025-01-10T10:23:27.216Z pid=47763 tid=15bv class=SimpleWorker jid=38c1f5938b17233b4e0b842b INFO: rails logger says hi
2025-01-10T10:23:27.217Z pid=47763 tid=15bv class=SimpleWorker jid=38c1f5938b17233b4e0b842b elapsed=0.069 INFO: done

Actual Behavior

RailsSemanticLogger only tags it with the jid by default:

2025-01-10 10:28:59.471449 I [48258:sidekiq.default/processor] {jid: f82aa891af96cbda43fc2981, queue: default} SimpleWorker -- Start #perform
2025-01-10 10:28:59.479035 I [48258:sidekiq.default/processor] {jid: f82aa891af96cbda43fc2981, queue: default} SimpleWorker -- Hello world
2025-01-10 10:28:59.523899 I [48258:sidekiq.default/processor] {jid: f82aa891af96cbda43fc2981, queue: default} Rails -- rails logger says hi
2025-01-10 10:28:59.525212 I [48258:sidekiq.default/processor] {jid: f82aa891af96cbda43fc2981, queue: default} (53.7ms) SimpleWorker -- Completed #perform

which can make it hard to keep track of which job is responsible for some nested log statement coming from ActiveRecord or whatever.

Pull requests

For now I'm monkeypatching it:

RailsSemanticLogger::Sidekiq::JobLogger.class_eval do
  def job_hash_context(job_hash)
    h         = { jid: job_hash["jid"], class: job_hash["wrapped"] || job_hash["class"] }
    h[:bid]   = job_hash["bid"] if job_hash["bid"]
    h[:tags]  = job_hash["tags"] if job_hash["tags"]
    h[:queue] = job_hash["queue"] if job_hash["queue"]
    h
  end
end

but I can submit a PR if this seems like a good idea

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

No branches or pull requests

1 participant