-
Notifications
You must be signed in to change notification settings - Fork 655
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
Migrate log traces to new Carto::Common::Logger #15776
Migrate log traces to new Carto::Common::Logger #15776
Conversation
d21438d
to
6f5d1fe
Compare
de8dc84
to
84d0b8e
Compare
Fix for undefined method `in_database_direct_connection' in georeferencer (imports) by going back to Sequel ::User model
86fd989
to
8bdb03b
Compare
It seems like the spec helper is not loading the initialization. There may be better ways to fix it, but right now not worth the effort IMO.
The code checked that no error was reported with CartoDB::Logger before. But syncs and imports use their own logger, so it didn't make sense anyway. Aside, I checked and the exceptions are all being captured and dealt with and do not bubble up, so the errors because of the exceptions I think are due to an unwanted interaction with the test framework. Anyway, both tests and code are perfectly functional, so removing that extra check.
We were rescuing an exception just to raise it again, but with the disadvantage of losing all the original info such as the stacktrace
It's giving me a lot of problems, and it says: "it's not a complete sync test" So I'd rather keep the useful ones.
This reverts commit 0522c8f.
Fix calling logger methods from a class method
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.
Nice job with log_context
. Nice distinction between current_user
and target_user
.
So good the file lib/cartodb/logger.rb
is deleted.
I think the only change needed is to rollback the deletion of remaining_days_deletion
@@ -91,9 +90,6 @@ def rescue_from_record_not_found | |||
|
|||
def rescue_from_central_error(error) | |||
log_rescue_from(__method__, error) | |||
CartoDB::Logger.error(exception: error, |
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.
A bit off-topic: this coming from central, and the same way we add extra info for oauth errors, we may eventually want to add extra info about the error (but perhaps this is not the right place for it).
@rafatower thanks for the suggestions 🙂 . I've applied some of them in the last commit. Tomorrow I'll test this in staging. |
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.
Awesome job :)
Related: https://app.clubhouse.io/cartoteam/story/91596/migrate-log-traces-to-new-carto-logger
What does this PR do?
CartoDB::Logger
per the newCarto::Common::Logger
(wrapped by::LoggerHelper
)rescue
blocksLogging context
Log messages are processed by our ELK stack. Each log message maps into a set of fields, which then are inserted in Elaticsearch. These fields have an associated type, which is automatically assigned by Elaticsearch when a new field name is received.
This has the caveat that if a subsequent log message is received with the same field name but a different type (ex:
1
vs"1"
), the log message is lost because the insertion in the Elasticsearch index fails.To mitigate this, please review existing logging messages to check the format used and existing logging conventions before writing new entries. I know this is not ideal, but solving it exceeds the scope of this PR.
Logging guidelines
1. Avoid using very-generic names when naming log fields
For example, if you do:
This would prevent from someone afterwards doing the following:
2. Use nested attributes when possible
Use:
Instead of:
(!!) This is subject to future change or debate, but for the time being I opted for this approach.
3. Try to reuse existing fields when possible
This is a list of the more common ones:
message
- Self-descriptive. Maps toevent_message
in Kibana.current_user
- Username of the user performing (or affected by) this action. Maps tocdb-user
in Kibana. TheLoggerHelper
automatically serializesUser
andCarto::User
objects received in this field toCarto::User#username
.target_user
- Use this field only when the action of the action is not the same as the affected user. For example, in the context of an organization admin deleting an organization user, thecurrent_user
would be the admin and thetarget_user
the deleted user. TheLoggerHelper
automatically serializesUser
andCarto::User
objects received in this field toCarto::User#username
.organization
- Name of the organization (if present). TheLoggerHelper
automatically serializesOrganization
andCarto::Organization
objects received in this field toCarto::Organization#name
.exception
- AnException
object. It's automatically serialized byLoggerHelper
error_detail
- A string giving more details of an error. For example those present inuser.errors.full_messages
after running ActiveRecord valiations.4. Be conservative about logged in formation
5. Try to abstract common logger information
If the logging messages written in a class share a set of common fields, try to abstract it by defining a
log_context
method.For example:
Suggestions for future work
config/initializers/error_notifier.rb
ResqueFailureLogger
toCarto::Common::JobLogger