hedera-json-rpc-relay icon indicating copy to clipboard operation
hedera-json-rpc-relay copied to clipboard

Improve info in case of tracing activities

Open Neurone opened this issue 2 years ago • 3 comments

Description: While conducting debug activities you often enable trace log level, and you want to check the actual requests and response between client and server (i.e., #1802).

This PR:

  • adds info about request and response bodies when trace log level is enabled.
  • reduces the default log level to info instead of trace

Related issue(s):

N/A

Notes for reviewer:

N/A

Checklist

  • [x] Documented (Code comments, README, etc.)
  • [x] Tested (unit, integration, etc.)

Neurone avatar Oct 11 '23 14:10 Neurone

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Oct 11 '23 14:10 sonarqubecloud[bot]

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (63953ee) 77.73% compared to head (53bdad4) 77.75%.

:exclamation: Current head 53bdad4 differs from pull request most recent head 748d373. Consider uploading reports for the commit 748d373 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1817      +/-   ##
==========================================
+ Coverage   77.73%   77.75%   +0.02%     
==========================================
  Files          40       40              
  Lines        3023     3026       +3     
  Branches      603      603              
==========================================
+ Hits         2350     2353       +3     
  Misses        489      489              
  Partials      184      184              
Files Coverage Δ
packages/server/src/koaJsonRpc/index.ts 68.22% <100.00%> (+0.60%) :arrow_up:
packages/server/src/server.ts 69.51% <100.00%> (+0.12%) :arrow_up:

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 11 '23 14:10 codecov-commenter

Hi Nana, those lines show the payload sent by the client and the relay's response, so it depends.

Adding those logs was essential, for example, to track down the bug described in #1802, and here is an example of what you can see before and after adding that tracing while receiving requests for that use case:

Old log, with LOG_LEVEL="trace"

[2023-10-19 15:21:47.525 +0000] WARN (koa-rpc/14646 on devmachine2204): [6c2eb549-3a47-4a8e-91a6-d121ce23aaef] Invalid request, body.jsonrpc: undefined, body[method]: undefined, body[id]: undefined, ctx.request.method: POST
[2023-10-19 15:21:47.525 +0000] INFO (rpc-server/14646 on devmachine2204): [Request ID: 6c2eb549-3a47-4a8e-91a6-d121ce23aaef] [POST]: undefined 400 (INVALID REQUEST) 0 ms

New log, with LOG_LEVEL="trace"

[2023-10-19 15:25:13.343 +0000] TRACE (koa-rpc/16392 on devmachine2204): [Request ID: 45991684-7965-4875-b298-d54423f2516d] Request body [{"method":"eth_chainId","params":[],"id":2,"jsonrpc":"2.0"},{"method":"eth_blockNumber","params":[],"id":3,"jsonrpc":"2.0"}]
[2023-10-19 15:25:13.343 +0000] WARN (koa-rpc/16392 on devmachine2204): [45991684-7965-4875-b298-d54423f2516d] Invalid request, body.jsonrpc: undefined, body[method]: undefined, body[id]: undefined, ctx.request.method: POST
[2023-10-19 15:25:13.343 +0000] INFO (rpc-server/16392 on devmachine2204): [Request ID: 45991684-7965-4875-b298-d54423f2516d] [POST]: undefined 400 (INVALID REQUEST) 1 ms
[2023-10-19 15:25:13.343 +0000] TRACE (rpc-server/16392 on devmachine2204): [Request ID: 45991684-7965-4875-b298-d54423f2516d] [POST]: undefined 400 (INVALID REQUEST) {"error":{"message":"Invalid Request","code":-32600},"jsonrpc":"2.0","id":null}

The log's type is trace, so the maximum logging level. As a developer, when I enable that level of logging, I expect to receive many messages to track as many details as possible about what's happening.

To avoid bloating the log files, I also suggested changing the default log level from trace to info in this PR.

Neurone avatar Oct 19 '23 15:10 Neurone

PR #3133 Updates the configuration doc to list the default LOG_LEVEL for now.

ebadiere avatar Oct 18 '24 20:10 ebadiere