Skip to content

Add job_id and exception message to ActiveJob retry/discard logging - #42990

Merged
matthewd merged 1 commit into
rails:mainfrom
jrochkind:active_job_logging
Feb 9, 2022
Merged

Add job_id and exception message to ActiveJob retry/discard logging#42990
matthewd merged 1 commit into
rails:mainfrom
jrochkind:active_job_logging

Conversation

@jrochkind

Copy link
Copy Markdown
Contributor

In other log messages like perform/performed and ActiveJob error logging, the job ID and exception message were already included, eg:

Error performing TestFailureJob (Job ID: d70ad13e-e58b-409c-a8cc-e0447fc792b5) from Resque(default) in 1446.56ms: RuntimeError (Error Message):

But log messages related to retry/discard behavior from ActiveJob::Exceptions did not include the Job ID or exception message. We now include them, in a consistent format with other existing messages.

Job ID is especially useful because, while other ActiveJob-related log messages get the Job ID via tagged logging, retry-related log messages do not currently end up tagged with Job ID. And it's really useful to use Job ID to be able to collect all the log lines related to a particular job, put the error messages together with the retry and subsequent perform messages.

We also include job.executions in the enqueue_retry log message because it was available and useful, to know if this is the 1st retry or 2nd or whatever. Previously job.executions was included in retry_stopped logging, but not enqueue_retry.

@rails-bot rails-bot Bot added the activejob label Aug 10, 2021
@jrochkind

jrochkind commented Aug 11, 2021

Copy link
Copy Markdown
Contributor Author

I'm sorry I don't understand what to do with that build failure, I think it's unrelated?

I am not familiar with this build system (I think Rails has changed it since I last looked at a Rails CI), but I think maybe actual automated tests were run anyway and green? Not sure.

The error I can find in build output is related to npm/webpacker, and my PR touched nothing related to JS, so.

error @rails/[email protected]: The engine "node" is incompatible with this module. Expected version "^12 \|\| >=14". Got "10.24.1"
--
  | error Found incompatible module.
  | info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
  | ERROR: Service 'base' failed to build: The command '/bin/sh -c mv -f tmp/Gemfile.lock.updated Gemfile.lock     && if [ -f package.json ]; then         echo "--- :javascript: Building JavaScript package"         && (cd actionview && yarn build)         && if [ -f railties/test/isolation/assets/package.json ]; then             (cd railties/test/isolation/assets && yarn install);         fi         && yarn cache clean;     fi' returned a non-zero code: 1
  | 🚨 Error: The command exited with status 1

@rails-bot

rails-bot Bot commented Nov 9, 2021

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot Bot added the stale label Nov 9, 2021
@jrochkind

jrochkind commented Nov 9, 2021

Copy link
Copy Markdown
Contributor Author

I would still love for this to be considered for merge. Will rebase.

@rails-bot rails-bot Bot removed the stale label Nov 9, 2021
@jrochkind
jrochkind force-pushed the active_job_logging branch 2 times, most recently from 1eb6a8d to b260bb8 Compare November 9, 2021 22:23
@rails-bot

rails-bot Bot commented Feb 7, 2022

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot Bot added the stale label Feb 7, 2022
@jrochkind

jrochkind commented Feb 7, 2022

Copy link
Copy Markdown
Contributor Author

I would still love to see this reviewed/merged, I think it is a pretty simple improvement to ActiveJob logging to make it more internally consistent and predictable. I have had to monkey-patch my own Rails to add it; I think all would benefit from it.

I guess I'm just gonna keep posting that everytime rails bot tries to mark it stale!

@rails-bot rails-bot Bot removed the stale label Feb 7, 2022
@matthewd

matthewd commented Feb 8, 2022

Copy link
Copy Markdown
Member

Job ID is especially useful because, while other ActiveJob-related log messages get the Job ID via tagged logging, retry-related log messages do not currently end up tagged with Job ID.

I wonder if it would be practical for us to solve it at this layer (i.e., by arranging to tag those log messages). I imagine people who parse and group logs based on tags during ingestion into some log system might prefer that consistency. 🤔

Failure looks real:

https://buildkite.com/rails/rails/builds/82441#1486d9db-ae9c-4aef-9354-c51ae55199a7/1013-1028

Could not log "enqueue_retry.active_job" event. NameError: undefined local variable or method `job_executions' for #<ActiveJob::LogSubscriber:...

In other log messages like perform/performed and ActiveJob error logging, the job ID and exception message were already included, eg:

    Error performing TestFailureJob (Job ID: d70ad13e-e58b-409c-a8cc-e0447fc792b5) from Resque(default) in 1446.56ms: RuntimeError (Error Message):

But log message related to retry/discard behavior from ActiveJob::Exceptions did not include the Job ID or exception message. We now include them, in a consistent format with other existing messages.

Job ID is especially useful because, while other ActiveJob-related log messages get the Job ID via tagged logging, retry-related log messages do not currently end up tagged with Job ID. And it's really useful to use Job ID to be able to collect all the log lines related to a particular job, put the error messages together with the retry and subsequent perform messages.

We also include job.executions in the enqueue_retry log message because it was available and useful, to know if this is the 1st retry or 2nd or whatever. Previously job.executions was included in retry_stopped logging, but not enqueue_retry.
@jrochkind

Copy link
Copy Markdown
Contributor Author

Thanks so much for feedback @matthewd !

I have fixed the typo error caught by CI now that it was working! And rebased on main branch -- build is now green!

I wonder if it would be practical for us to solve it at this layer (i.e., by arranging to tag those log messages).

It does sound like a good solution to get ActiveJob logging to automatically tag with "Job ID". it's a bit beyond my knowledge/energy to do that at present.

The logging was already including JobID in some log messages but not others; this PR keeps the same architecture that was there before without adding/changing anything, just makes all log messages consistent with info and formatting. Perhaps that's a reasonable step.

@matthewd

matthewd commented Feb 9, 2022

Copy link
Copy Markdown
Member

The logging was already including JobID in some log messages but not others

Yep, fair point 👍🏻

Thanks! (And thanks for persevering through the silence)

@matthewd
matthewd merged commit e483bc5 into rails:main Feb 9, 2022
@jrochkind

Copy link
Copy Markdown
Contributor Author

Thank you @matthewd !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants