Page MenuHomePhabricator

[identity] Add prefixes to error logs for filtering
ClosedPublic

Authored by will on Wed, May 1, 8:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, May 12, 2:02 PM
Unknown Object (File)
Sun, May 12, 7:59 AM
Unknown Object (File)
Sat, May 11, 9:30 PM
Unknown Object (File)
Tue, May 7, 9:01 PM
Unknown Object (File)
Tue, May 7, 9:01 PM
Unknown Object (File)
Tue, May 7, 9:00 PM
Unknown Object (File)
Tue, May 7, 11:34 AM
Unknown Object (File)
Mon, May 6, 8:59 PM
Subscribers

Details

Summary

This adds prefixes to our error! tracing logs on the identity service

Depends on D11831

Test Plan

cargo check

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

will requested review of this revision.Wed, May 1, 8:20 PM
varun requested changes to this revision.Thu, May 2, 11:28 AM

I was imagining that all the prefixes (e.g. DB Error) would be defined in a module in constants.rs and then used like this:

pub const DB_ERROR_LOG_PREFIX: &str = "DB Error";

error!(DB_ERROR_LOG_PREFIX, "Encountered an unexpected error: {}", e);
This revision now requires changes to proceed.Thu, May 2, 11:28 AM

I was imagining that all the prefixes (e.g. DB Error) would be defined in a module in constants.rs and then used like this:

pub const DB_ERROR_LOG_PREFIX: &str = "DB Error";

error!(DB_ERROR_LOG_PREFIX, "Encountered an unexpected error: {}", e);

So that would look something like this on output:

{"message":"Encountered an unexpected error: e","DB_ERROR_LOG_PREFIX":"DB Error"}

Currently my alarms match on the message field. I think it overcomplicates the cloudwatch patterns if we're accessing each possible prefix variable name so what might be best is each error log specifies some field:

error!(errorType=DB_ERROR_LOG_PREFIX, "Encountered an unexpected error: {}", e);

would get us:

{"message":"Encountered an unexpected error: e", "errorType":"DB Error"}

I thought about how we'd be able to store the key value "errorType = DB_ERROR_LOG_PREFIX" in our const file so we wouldn't have to include errorType each time, but I don't think it's possible unless we do something really hacky with mods

Another option is a new error log helper function?

@varun's concern is valid to me. I like the errorType = ... approach.

In D11852#339879, @will wrote:

what might be best is each error log specifies some field:

error!(errorType=DB_ERROR_LOG_PREFIX, "Encountered an unexpected error: {}", e);

would get us:

{"message":"Encountered an unexpected error: e", "errorType":"DB Error"}

I thought about how we'd be able to store the key value "errorType = DB_ERROR_LOG_PREFIX" in our const file so we wouldn't have to include errorType each time, but I don't think it's possible unless we do something really hacky with mods

I think including errorType in each log is okay for now. If this gets too annoying, we can think about creating a custom error! macro

bartek added inline comments.
services/identity/src/constants.rs
196–206 ↗(On Diff #39870)

Optionally it could be done this way, so instead of doing errorType = GENERIC_DB_LOG_ERROR_TYPE, it would be errorType = error_types::GENERIC_DB_LOG.

Both approaches are okay to me

services/identity/src/constants.rs
196–206 ↗(On Diff #39870)

I like your way better. It's more organized. Will include in the next rebase

review feedback and whitespace

bartek removed a reviewer: varun.

@varun is off but his feedback has been addressed so unblocking this stack

This revision is now accepted and ready to land.Tue, May 7, 9:47 AM
This revision was automatically updated to reflect the committed changes.
will marked an inline comment as done.