-
Notifications
You must be signed in to change notification settings - Fork 384
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
fix: improve logging structure #1583
Merged
Merged
+260
−115
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pull Request Test Coverage Report for Build 9111276456Details
💛 - Coveralls |
kangmingtay
force-pushed
the
km/fix-logging
branch
from
May 15, 2024 09:15
579d7c6
to
cd4d7eb
Compare
J0
approved these changes
May 16, 2024
kangmingtay
force-pushed
the
km/fix-logging
branch
from
May 16, 2024 09:04
a05ee64
to
de45b3f
Compare
kangmingtay
force-pushed
the
km/fix-logging
branch
from
May 16, 2024 11:14
2b20094
to
f26ab6e
Compare
J0
pushed a commit
that referenced
this pull request
May 22, 2024
🤖 I have created a release *beep* *boop* --- ## [2.152.0](v2.151.0...v2.152.0) (2024-05-22) ### Features * new timeout writer implementation ([#1584](#1584)) ([72614a1](72614a1)) * remove legacy lookup in users for one_time_tokens (phase II) ([#1569](#1569)) ([39ca026](39ca026)) * update chi version ([#1581](#1581)) ([c64ae3d](c64ae3d)) * update openapi spec with identity and is_anonymous fields ([#1573](#1573)) ([86a79df](86a79df)) ### Bug Fixes * improve logging structure ([#1583](#1583)) ([c22fc15](c22fc15)) * sms verify should update is_anonymous field ([#1580](#1580)) ([e5f98cb](e5f98cb)) * use api_external_url domain as localname ([#1575](#1575)) ([ed2b490](ed2b490)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
uxodb
pushed a commit
to uxodb/auth
that referenced
this pull request
Nov 13, 2024
## What kind of change does this PR introduce? * Remove unformatted logs which do not confirm to JSON * Previously, we were logging both `time` (not UTC) and `timestamp` (in UTC) which is redundant. I've opted to remove `timestamp` and just log the UTC time as the `time` field, which is supported by logrus * Previously, the `request_id` was not being logged because it was unable to retrieve the context properly. Now, the `request_id` field is added to every log entry, which allows us to filter by `request_id` to see the entire lifecycle of the request * Previously, panics weren't being handled properly and they were just logged as text instead of JSON. The server would return an empty reply, which leads to ugly responses like "Unexpected token < in JSON..." if using fetch in JS. Now, the server returns a proper 500 error response: `{"code":500,"error_code":"unexpected_failure","msg":"Internal Server Error"}` * Added tests for `recoverer` and `NewStructuredLogger` to prevent regression * Remove "request started" log since the `request_id` can be used to keep track of the entire request lifecycle. This cuts down on the noise to signal ratio as well. ## Log format * Panics are now logged like this (note the additional fields like `panic` and `stack` - which is a dump of the stack trace): ```json { "component":"api", "duration":6065700500, "level":"info", "method":"GET", "msg":"request completed", "panic":"test panic", "path":"/panic", "referer":"http://localhost:3001", "remote_addr":"127.0.0.1", "request_id":"4cde5f20-2c3c-4645-bc75-52d6231e22e2", "stack":"goroutine 82 [running]:...rest of stack trace omitted for brevity", "status":500, "time":"2024-05-15T09:37:42Z" } ``` * Requests that call `NewAuditLogEntry` will be logged with the `auth_event` payload in this format (note that the timestamp field no longer exists) ```json { "auth_event": { "action": "token_refreshed", "actor_id": "733fb34d-a6f2-43e1-976a-8e6a456b6889", "actor_name": "Kang Ming Tay", "actor_username": "kang.ming1996@gmail.com", "actor_via_sso": false, "log_type": "token" }, "component": "api", "duration": 75945042, "level": "info", "method": "POST", "msg": "request completed", "path": "/token", "referer": "http://localhost:3001", "remote_addr": "127.0.0.1", "request_id": "08c7e47b-42f4-44dc-a39b-7275ef5bbb45", "status": 200, "time": "2024-05-15T09:40:09Z" } ```
uxodb
pushed a commit
to uxodb/auth
that referenced
this pull request
Nov 13, 2024
🤖 I have created a release *beep* *boop* --- ## [2.152.0](supabase/auth@v2.151.0...v2.152.0) (2024-05-22) ### Features * new timeout writer implementation ([supabase#1584](supabase#1584)) ([72614a1](supabase@72614a1)) * remove legacy lookup in users for one_time_tokens (phase II) ([supabase#1569](supabase#1569)) ([39ca026](supabase@39ca026)) * update chi version ([supabase#1581](supabase#1581)) ([c64ae3d](supabase@c64ae3d)) * update openapi spec with identity and is_anonymous fields ([supabase#1573](supabase#1573)) ([86a79df](supabase@86a79df)) ### Bug Fixes * improve logging structure ([supabase#1583](supabase#1583)) ([c22fc15](supabase@c22fc15)) * sms verify should update is_anonymous field ([supabase#1580](supabase#1580)) ([e5f98cb](supabase@e5f98cb)) * use api_external_url domain as localname ([supabase#1575](supabase#1575)) ([ed2b490](supabase@ed2b490)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
LashaJini
pushed a commit
to LashaJini/auth
that referenced
this pull request
Nov 13, 2024
## What kind of change does this PR introduce? * Remove unformatted logs which do not confirm to JSON * Previously, we were logging both `time` (not UTC) and `timestamp` (in UTC) which is redundant. I've opted to remove `timestamp` and just log the UTC time as the `time` field, which is supported by logrus * Previously, the `request_id` was not being logged because it was unable to retrieve the context properly. Now, the `request_id` field is added to every log entry, which allows us to filter by `request_id` to see the entire lifecycle of the request * Previously, panics weren't being handled properly and they were just logged as text instead of JSON. The server would return an empty reply, which leads to ugly responses like "Unexpected token < in JSON..." if using fetch in JS. Now, the server returns a proper 500 error response: `{"code":500,"error_code":"unexpected_failure","msg":"Internal Server Error"}` * Added tests for `recoverer` and `NewStructuredLogger` to prevent regression * Remove "request started" log since the `request_id` can be used to keep track of the entire request lifecycle. This cuts down on the noise to signal ratio as well. ## Log format * Panics are now logged like this (note the additional fields like `panic` and `stack` - which is a dump of the stack trace): ```json { "component":"api", "duration":6065700500, "level":"info", "method":"GET", "msg":"request completed", "panic":"test panic", "path":"/panic", "referer":"http://localhost:3001", "remote_addr":"127.0.0.1", "request_id":"4cde5f20-2c3c-4645-bc75-52d6231e22e2", "stack":"goroutine 82 [running]:...rest of stack trace omitted for brevity", "status":500, "time":"2024-05-15T09:37:42Z" } ``` * Requests that call `NewAuditLogEntry` will be logged with the `auth_event` payload in this format (note that the timestamp field no longer exists) ```json { "auth_event": { "action": "token_refreshed", "actor_id": "733fb34d-a6f2-43e1-976a-8e6a456b6889", "actor_name": "Kang Ming Tay", "actor_username": "kang.ming1996@gmail.com", "actor_via_sso": false, "log_type": "token" }, "component": "api", "duration": 75945042, "level": "info", "method": "POST", "msg": "request completed", "path": "/token", "referer": "http://localhost:3001", "remote_addr": "127.0.0.1", "request_id": "08c7e47b-42f4-44dc-a39b-7275ef5bbb45", "status": 200, "time": "2024-05-15T09:40:09Z" } ```
LashaJini
pushed a commit
to LashaJini/auth
that referenced
this pull request
Nov 13, 2024
🤖 I have created a release *beep* *boop* --- ## [2.152.0](supabase/auth@v2.151.0...v2.152.0) (2024-05-22) ### Features * new timeout writer implementation ([supabase#1584](supabase#1584)) ([72614a1](supabase@72614a1)) * remove legacy lookup in users for one_time_tokens (phase II) ([supabase#1569](supabase#1569)) ([39ca026](supabase@39ca026)) * update chi version ([supabase#1581](supabase#1581)) ([c64ae3d](supabase@c64ae3d)) * update openapi spec with identity and is_anonymous fields ([supabase#1573](supabase#1573)) ([86a79df](supabase@86a79df)) ### Bug Fixes * improve logging structure ([supabase#1583](supabase#1583)) ([c22fc15](supabase@c22fc15)) * sms verify should update is_anonymous field ([supabase#1580](supabase#1580)) ([e5f98cb](supabase@e5f98cb)) * use api_external_url domain as localname ([supabase#1575](supabase#1575)) ([ed2b490](supabase@ed2b490)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
LashaJini
pushed a commit
to LashaJini/auth
that referenced
this pull request
Nov 15, 2024
## What kind of change does this PR introduce? * Remove unformatted logs which do not confirm to JSON * Previously, we were logging both `time` (not UTC) and `timestamp` (in UTC) which is redundant. I've opted to remove `timestamp` and just log the UTC time as the `time` field, which is supported by logrus * Previously, the `request_id` was not being logged because it was unable to retrieve the context properly. Now, the `request_id` field is added to every log entry, which allows us to filter by `request_id` to see the entire lifecycle of the request * Previously, panics weren't being handled properly and they were just logged as text instead of JSON. The server would return an empty reply, which leads to ugly responses like "Unexpected token < in JSON..." if using fetch in JS. Now, the server returns a proper 500 error response: `{"code":500,"error_code":"unexpected_failure","msg":"Internal Server Error"}` * Added tests for `recoverer` and `NewStructuredLogger` to prevent regression * Remove "request started" log since the `request_id` can be used to keep track of the entire request lifecycle. This cuts down on the noise to signal ratio as well. ## Log format * Panics are now logged like this (note the additional fields like `panic` and `stack` - which is a dump of the stack trace): ```json { "component":"api", "duration":6065700500, "level":"info", "method":"GET", "msg":"request completed", "panic":"test panic", "path":"/panic", "referer":"http://localhost:3001", "remote_addr":"127.0.0.1", "request_id":"4cde5f20-2c3c-4645-bc75-52d6231e22e2", "stack":"goroutine 82 [running]:...rest of stack trace omitted for brevity", "status":500, "time":"2024-05-15T09:37:42Z" } ``` * Requests that call `NewAuditLogEntry` will be logged with the `auth_event` payload in this format (note that the timestamp field no longer exists) ```json { "auth_event": { "action": "token_refreshed", "actor_id": "733fb34d-a6f2-43e1-976a-8e6a456b6889", "actor_name": "Kang Ming Tay", "actor_username": "kang.ming1996@gmail.com", "actor_via_sso": false, "log_type": "token" }, "component": "api", "duration": 75945042, "level": "info", "method": "POST", "msg": "request completed", "path": "/token", "referer": "http://localhost:3001", "remote_addr": "127.0.0.1", "request_id": "08c7e47b-42f4-44dc-a39b-7275ef5bbb45", "status": 200, "time": "2024-05-15T09:40:09Z" } ```
LashaJini
pushed a commit
to LashaJini/auth
that referenced
this pull request
Nov 15, 2024
🤖 I have created a release *beep* *boop* --- ## [2.152.0](supabase/auth@v2.151.0...v2.152.0) (2024-05-22) ### Features * new timeout writer implementation ([supabase#1584](supabase#1584)) ([72614a1](supabase@72614a1)) * remove legacy lookup in users for one_time_tokens (phase II) ([supabase#1569](supabase#1569)) ([39ca026](supabase@39ca026)) * update chi version ([supabase#1581](supabase#1581)) ([c64ae3d](supabase@c64ae3d)) * update openapi spec with identity and is_anonymous fields ([supabase#1573](supabase#1573)) ([86a79df](supabase@86a79df)) ### Bug Fixes * improve logging structure ([supabase#1583](supabase#1583)) ([c22fc15](supabase@c22fc15)) * sms verify should update is_anonymous field ([supabase#1580](supabase#1580)) ([e5f98cb](supabase@e5f98cb)) * use api_external_url domain as localname ([supabase#1575](supabase#1575)) ([ed2b490](supabase@ed2b490)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
time
(not UTC) andtimestamp
(in UTC) which is redundant. I've opted to removetimestamp
and just log the UTC time as thetime
field, which is supported by logrusrequest_id
was not being logged because it was unable to retrieve the context properly. Now, therequest_id
field is added to every log entry, which allows us to filter byrequest_id
to see the entire lifecycle of the request{"code":500,"error_code":"unexpected_failure","msg":"Internal Server Error"}
recoverer
andNewStructuredLogger
to prevent regressionrequest_id
can be used to keep track of the entire request lifecycle. This cuts down on the noise to signal ratio as well.Log format
panic
andstack
- which is a dump of the stack trace):NewAuditLogEntry
will be logged with theauth_event
payload in this format (note that the timestamp field no longer exists)